java - NoSuchElementException : Unable to find element with id/Works fine in FireFox and Chrome but not in IE

标签 java eclipse internet-explorer selenium selenium-webdriver

我在 Eclipse 中使用以下代码,该代码在 FireFox 和 Chrome 中都可以正常工作(显然我在这些测试用例中不会调用 IE webdriver),但在 IE10 中则不然,该代码在 assertTrue 部分失败。因此,下面的代码打开 IE 浏览器窗口,打开请求的 URL,填写用户名和密码,然后单击“确定”按钮。登录成功,我想确认我是否以我使用的用户名和密码的用户身份登录。

public void test3() throws Exception {
System.setProperty("webdriver.ie.driver", "browsers\\IEDriverServer.exe");

/** Test: Start Browser*/
driver=new InternetExplorerDriver();
driver.manage().window().maximize();

/** Test: Login is possible*/
driver.get ("http://URL/");
driver.findElement(By.id("Username")).clear();
driver.findElement(By.id("Username")).sendKeys("testname");
driver.findElement(By.id("Password")).clear();
driver.findElement(By.id("Password")).sendKeys("Welcome01");
driver.findElement(By.xpath("//input[@id='']")).click();

/** Test: logged in as user confirmation*/
assertTrue(driver.findElement(By.id("dvPageOptions")).getText().contains("testname"));

driver.quit();

这会引发错误:

org.openqa.selenium.NoSuchElementException: Unable to find element with id == dvPageOptions (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 274 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46' System info: host: 'BA91-CNU21923BJ', ip: '10.55.17.73', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_31' Driver info: org.openqa.selenium.ie.InternetExplorerDriver

这是页面源码的一部分

    < div id="dvPageOptions" style='display:inline;position:absolute;right:10px'>
logged in as: testname</div >

如您所见,我要断言的 ID 和内容位于源代码中。

附加信息: 我使用的是 IE10,安全设置均正确(所有区域均启用保护模式)

最佳答案

谢谢你,吉里什· Solr 图尔!正如您提到的,id 加载有点晚,所以我决定加入等待操作(见下文)。现在一切正常了!

WebDriverWait wait = new WebDriverWait(driver,120);
wait.until(ExpectedConditions.elementToBeClickable(By.id("GoTo")));
assertTrue(driver.findElement(By.id("dvPageOptions")).getText().contains("testname"));

关于java - NoSuchElementException : Unable to find element with id/Works fine in FireFox and Chrome but not in IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32651255/

相关文章:

css - 将单个 Stylus 源文件中的样式分离到不同的 CSS 文件中

java - 从 Eclipse 导出后 System.out.println 不打印

java - 有什么方法可以在单个 catch 子句(OLD JAVA VERSIONS)中捕获多个 Java 异常?

java - 在 tomcat 中运行多个应用程序时,Struts2 应用程序中的 NullpointerException

java - 如何使用 Moshi 将 int 数组反序列化为自定义类?

eclipse - 在 JDT dom 中使用 class 作为字段名称

java进程和输入流

java - 安装安卓 SDK 23

internet-explorer - 测试浏览器插件的性能,内存泄漏,页面加载等

javascript - 对 ie6 用户隐藏 CSS 和 HTML?