简体   繁体   中英

driver.findElement() with iframe and elements without ID

Java Code:

driver.switchTo().frame(0);
                WebElement elemText = driver.findElement(By.xpath("/html/body[contains(@class='forum')]"));
                //WebElement elemText = driver.findElement(By.xpath("//td[@id='cke_contents_vB_Editor_001_editor']/textarea"));
                elemText.sendKeys(message);
                elemText.submit();
                forumLink =  driver.getCurrentUrl();

HTML Code:

<td id="cke_contents_vB_Editor_001_editor" class="cke_contents" style="height:1726px" role="presentation">
<iframe style="width:100%;height:100%" frameborder="0" title="Rich text editor, vB_Editor_001_editor, press ALT 0 for help." src="" tabindex="-1" allowtransparency="true">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html dir="ltr" lang="en" contenteditable="true">
<head>
<title data-cke-title="Rich text editor, vB_Editor_001_editor, press ALT 0 for help.">Rich text editor, vB_Editor_001_editor, press ALT 0 for help.</title>
<base href="http://fairplay.garena.com/" data-cke-temp="1">
<link type="text/css" rel="stylesheet" href="http://fairplay.garena.com/clientscript/vbulletin_css/style00008l/editor_contents.css">

<style type="text/css" data-cke-temp="1">
form{border: 1px dotted #FF0000;padding: 2px;}

img.cke_hidden{background-image: url(http://fairplay.garena.com/clientscript/ckeditor/plugins/forms/images/hiddenfield.gif?t=B37D54V);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 16px !important;height: 16px !important;}
img.cke_iframe{background-image: url(http://fairplay.garena.com/clientscript/ckeditor/plugins/iframe/images/placeholder.png?t=B37D54V);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 80px;height: 80px;}
img.cke_anchor{background-image: url(http://fairplay.garena.com/clientscript/ckeplugins/vblink/images/anchor.gif?t=B37D54V);background-position: center center;background-repeat: no-repeat;border: 1px solid #a9a9a9;width: 18px !important;height: 18px !important;}
a.cke_anchor{background-image: url(http://fairplay.garena.com/clientscript/ckeplugins/vblink/images/anchor.gif?t=B37D54V);background-position: left center;background-repeat: no-repeat;border: 1px solid #a9a9a9;padding-left: 18px;}
</style>
</head>
<body class="forum" spellcheck="true">
</body>
</html>
</iframe>
</td>

Image: http://s9.postimage.org/nwyvq3san/Screen_Shot038.jpg

I can't find a way to get elements inside a iframe and without id.

Can you help me?

driver.switchTo().frame(driver.findElementByXpath("//iframe"));
WebElement elemText = driver.findElement(By.xpath("//body[@class='forum')]"));

should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM