Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.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/0/jpa/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
Java NoSuchElementException:在FireFox和Chrome中找不到id为的元素,但在IE中找不到_Java_Eclipse_Internet Explorer_Selenium_Selenium Webdriver - Fatal编程技术网

Java NoSuchElementException:在FireFox和Chrome中找不到id为的元素,但在IE中找不到

Java NoSuchElementException:在FireFox和Chrome中找不到id为的元素,但在IE中找不到,java,eclipse,internet-explorer,selenium,selenium-webdriver,Java,Eclipse,Internet Explorer,Selenium,Selenium Webdriver,我在Eclipse中使用了以下代码,该代码在FireFox和Chrome中都可以正常工作(显然,在这些测试用例中我没有调用IE webdriver),但在IE10中没有,该代码在assertTrue部分失败。下面的代码打开IE浏览器窗口,打开请求的URL,填写用户名和密码,然后单击OK按钮。登录成功,我想确认我以我使用的用户名和密码的用户身份登录 public void test3() throws Exception { System.setProperty("webdriver.ie.dri

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

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:找不到元素 id==dvPageOptions(警告:服务器未提供任何 堆栈跟踪信息)命令持续时间或超时:274毫秒 有关此错误的文档,请访问: 构建信息: 版本:“2.47.1”,修订版:“411b314”,时间:“2015-07-30 02:56:46” 系统信息:主机:“BA91-CNU21923BJ”,ip:“10.55.17.73”,操作系统名称: 'Windows 7',os.arch:'x86',os.version:'6.1',java.version: “1.8.0_31”驱动程序信息:org.openqa.selenium.ie.InternetExplorerDriver

这是页面来源的一部分

    < div id="dvPageOptions" style='display:inline;position:absolute;right:10px'>
logged in as: testname</div >
登录身份:testname
如您所见,我希望断言的id和内容位于源代码中

其他信息:
我使用的是IE10,安全设置都正确(所有区域都启用了保护模式)

谢谢你,Girish Sortur!正如您提到的,id加载有点晚,所以我决定加入等待操作(见下文)。现在它工作得很好

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

谢谢你,小女孩索特!正如您提到的,id加载有点晚,所以我决定加入等待操作(见下文)。现在它工作得很好

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

看起来IE10浏览器有问题。你在IE11中试过吗?另外,
dvPageOptions
div在IE浏览器中加载是否有点晚,您可以手动测试并查看?不同浏览器之间的网页行为可能有所不同。例如,您导航到的URL可能在InternetExplorer中以不同方式打开。您可以尝试获取驱动程序.getPageSource(),并检查Internet Explorer页面中是否存在id为“dvPageOptions”的元素。IE10浏览器似乎存在问题。你在IE11中试过吗?另外,
dvPageOptions
div在IE浏览器中加载是否有点晚,您可以手动测试并查看?不同浏览器之间的网页行为可能有所不同。例如,您导航到的URL可能在InternetExplorer中以不同方式打开。您可以尝试获取driver.getPageSource()并检查Internet Explorer页面中是否存在id为“dvPageOptions”的元素。