Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.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 IE7-含硒的非接触元素异常_Java_Internet Explorer_Xpath_Selenium - Fatal编程技术网

Java IE7-含硒的非接触元素异常

Java IE7-含硒的非接触元素异常,java,internet-explorer,xpath,selenium,Java,Internet Explorer,Xpath,Selenium,我正在尝试在IE7和Windows XP上使用Selenium。这段代码在兼容模式下(在W7上)与Firefox、IE9甚至IE9都可以很好地配合使用 HTML: 并尝试获取我的#索引元素: log.info(driver.getPageSource()); try { String value = driver.findElement(By.cssSelector("#login")).toString(); log.info(value); } catch ( Except

我正在尝试在IE7和Windows XP上使用Selenium。这段代码在兼容模式下(在W7上)与Firefox、IE9甚至IE9都可以很好地配合使用

HTML:

并尝试获取我的
#索引
元素:

log.info(driver.getPageSource());

try {
    String value = driver.findElement(By.cssSelector("#login")).toString();
    log.info(value);
}
catch ( Exception e ) {
    log.error(e.toString());
}
页面源代码已正确获取,但每当我尝试访问元素时,都会得到一个
org.openqa.selenium.NoSuchElementException
。我还尝试了
id
XPath

知道出了什么问题吗

PS:在Windows XP中,IE没有安全模式

编辑:
driver.getPageSource()
返回:

<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"><HEAD><TITLE></TITLE></HEAD>
<BODY>
<DIV id=login>chicken</DIV></BODY></HTML>

确定-根据注释,您指定您没有针对中心运行,但在代码中-您指向中心。我认为这与此有关

更改此代码块:

try {
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
致:

RemoteWebDriver(新URL(“http://localhost:4444/wd/hub“”
这篇文章将您的测试指向某个远程驱动程序,这意味着“一个连接到集线器的selenium节点”。您已经确认,您没有使用集线器,因此这个答案应该可以解决您的问题

分项数字:

RemoteWebDriver() = Selenium Node that is connected to a hub
ChromeDriver|IEDriver|FirefoxDriver = Local browser session

对于IE 7,应该尝试一下selenium服务器2.20或更低版本。最近,我们遇到了类似的问题,即在IE 10中很少有命令可用,但在IE 8中没有命令。当我们降级到selenium 2.20(逐个尝试)时,它在IE 8和2.20中运行得很好。如果您使用的是hub,请确保运行selenium服务器的节点具有较旧的版本(在ie7下,当您告诉selenium打印页面源代码时会出现什么情况?您真的需要ie7和WinXP吗?我认为这两个版本在2014年4月都没有扩展支持。@acdcjunior它完全打印我在问题中给出的HTML代码,除了
div
是大写。@ChristianKuetbach不幸的是,这超出了我的控制范围,但我可以(不是WinXP,而是IE7)。如果使用
WebDriverWait
等待元素,会发生什么?我想你的意思是
new InternetExplorerDriver()
?这种方式简单得多(如果我理解正确,我连接到了一个本地节点),但它仍然不能解决问题。但无论如何,我会在兼容模式下坚持使用IE9。
try {
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
driver = new IEDriver(capabilities);
RemoteWebDriver() = Selenium Node that is connected to a hub
ChromeDriver|IEDriver|FirefoxDriver = Local browser session