[英]org.openqa.selenium.NoSuchElementException for IE11
这里是硒的新手,请保持友好。
我在带有Internet Explorer 11的Win 7上使用Selenium Webdriver 2.41.0,并得到以下“ org.openqa.selenium.NoSuchElementException:无法找到ID == home_title的元素(警告:服务器未提供任何堆栈跟踪信息) ”
我正在从属性文件中读取url和iedriverpath,随着浏览器使用有效的url启动,该段代码可以正常工作。
我其余的代码是
// Launches a browser based on the value specified in the properties file
public class LaunchBrowser {
public static WebDriver driver;
private String browser;
private String url;
private String iedriverpath;
// starts up a browser session and navigates to the url specified
@Test
public void startBrowser() throws Exception {
switch (browser) {
case "IE": // Set IE driver path
File ieFile = new File (iedriverpath);
System.setProperty("webdriver.ie.driver", ieFile.getAbsolutePath());
DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
dc.setCapability("nativeEvents", false);
driver = new InternetExplorerDriver(dc);
break;
default:
throw new IllegalArgumentException("Invalid Browser Specified!!!");
}
driver.get(url);
driver.manage().window().maximize();
WebElement ele = driver.findElement(By.id("home_title"));
}
}
我要查找的元素的HTML看起来像这样
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="33%" style="vertical-align:top;"></td>
<td width="33%" align="center">
<input id="home_title" class="home_title" type="text" readonly="true" title="Cloud Services" value="Cloud Services" style="width: 142px;">
</td>
<td class="text-align-right" width="33%" nowrap="true" style="vertical-align:top;">
</tr>
</tbody>
</table>
有什么想法可能导致异常吗? 是同步问题还是使用的定位器出现问题?
谢谢堆。
您需要切换框架。
driver.switchTo().frame("ID of frame");
然后做您的工作。。
driver.switchTo().defaultContent();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.