【问题标题】:IE7 - NoSuchElementException with SeleniumIE7 - 带有 Selenium 的 NoSuchElementException
【发布时间】:2013-11-24 19:15:25
【问题描述】:

我正在尝试在 IE7 上使用 Selenium,在 Windows XP 上使用 InternetExplorerDriver。此代码在兼容模式下(在 W7 上)适用于 Firefox、IE9 甚至 IE9。

HTML:

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

构建驱动程序:

private static WebDriver getIE7WebDriver() {
    WebDriver driver = null;
    DesiredCapabilities capabilities;
    capabilities= DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, false);
    capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS,true);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "internet explorer");
    capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
    capabilities.setCapability(CapabilityType.VERSION, "7");

    System.setProperty("webdriver.ie.driver",(new File("C:\\selenium\\IEDriverServer.exe")).getAbsolutePath());
    try {
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return driver;
}

并试图获取我的#index 元素:

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。我也试过idXPath

知道出了什么问题吗?

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>

【问题讨论】:

  • 在 ie7 下,告诉 selenium 打印页面源时会出现什么情况?
  • 你真的需要IE7和WinXP吗?我认为两者都在 2014 年 4 月不再提供扩展支持
  • @acdcjunior 它准确地打印出我在问题中给出的 HTML 代码,除了 div 是大写的。
  • @ChristianKuetbach 不幸的是,这超出了我的控制范围,但我可以(不是 WinXP,而是 IE7)。
  • 如果使用WebDriverWait 等待元素会发生什么?

标签: java internet-explorer xpath selenium


【解决方案1】:

好的 - 根据 cmets,您指定您没有针对集线器运行,但是,在您的代码中 - 您指向一个集线器。我认为这与此有关。

更改此代码块:

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(new URL("http://localhost:4444/wd/hub") 这篇文章将您的测试指向某个远程驱动程序,这意味着“连接到集线器的硒节点”。您已经确认您没有使用集线器,因此此答案应该解决您的问题。

细分:

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

【讨论】:

  • 我猜你的意思是new InternetExplorerDriver()?这种方式要简单得多(如果我理解正确,我已连接到本地节点),但它仍然不能解决问题。不过没关系,我会在兼容模式下坚持使用 IE9。
【解决方案2】:

对于 IE 7 selenium server 2.20 或以下版本应该试一试。最近我们遇到了类似的问题,其中很少有命令在 IE 10 中运行,但在 IE 8 中不起作用。当我们降级到 selenium 2.20(一一尝试)时,它在 IE 8 和 2.20 中运行良好。如果您使用的是集线器,请确保运行 selenium 服务器的节点运行的是较旧的 selenium 版本(

【讨论】:

    猜你喜欢
    • 2016-04-29
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2023-03-27
    • 2020-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多