Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有iframe的driver.findElement()和不带ID的元素_Java_Xpath_Selenium_Webdriver - Fatal编程技术网

Java 带有iframe的driver.findElement()和不带ID的元素

Java 带有iframe的driver.findElement()和不带ID的元素,java,xpath,selenium,webdriver,Java,Xpath,Selenium,Webdriver,Java代码: 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_

Java代码:

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代码:

<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>

富格文本编辑器,vB_编辑器_001_编辑器,按ALT 0以获取帮助。
表格{边框:1px点#FF0000;填充:2px;}
img.cke_隐藏{背景图像:url(http://fairplay.garena.com/clientscript/ckeditor/plugins/forms/images/hiddenfield.gif?t=B37D54V);背景位置:居中;背景重复:无重复;边框:1px实心#a9a9a9;宽度:16px!重要;高度:16px!重要;}
img.cke_iframe{背景图片:url(http://fairplay.garena.com/clientscript/ckeditor/plugins/iframe/images/placeholder.png?t=B37D54V);背景位置:居中;背景重复:无重复;边框:1px实心#A9A9;宽度:80px;高度:80px;}
img.cke_锚{背景图片:url(http://fairplay.garena.com/clientscript/ckeplugins/vblink/images/anchor.gif?t=B37D54V);背景位置:居中;背景重复:无重复;边框:1px实心#a9a9a9;宽度:18px!重要;高度:18px!重要;}
a、 cke_锚{背景图片:url(http://fairplay.garena.com/clientscript/ckeplugins/vblink/images/anchor.gif?t=B37D54V);背景位置:左中心;背景重复:无重复;边框:1px实心35; A9A9;左填充:18px;}
图片:

我找不到一种方法来获取iframe中没有id的元素

你能帮我吗

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


应该可以工作。

org.openqa.selenium.NoSuchFrameException:找不到frame://iframe命令持续时间或超时:15毫秒生成信息:版本:“2.24.1”,版本:“17205”,时间:“2012-06-19 15:28:49”系统信息:os.name:“Windows 2003”,os.arch:“x86”,os.version:“5.2”,java.ve rsion:'1.7.0_09'驱动程序信息:Driver.version:RemoteWebDriverorg.openqa.selenium.NoSuchFrameException:找不到frame://iframe命令持续时间或超时:15毫秒生成信息:版本:'2.24.1',版本:'17205',时间:'2012-06-19 15:28:49'系统信息:os.name:'Windows 2003',os.arch:'x86',os.version:'5.2',java.ve rsion:'1.7.0_09'驱动程序信息:Driver.version:RemoteWebDriver