Selenium InternetExplorerDriver无法找到明显存在的元素 [英] Selenium InternetExplorerDriver unable to find element that is clearly there

查看:172
本文介绍了Selenium InternetExplorerDriver无法找到明显存在的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些细节.

  • 代码:

    System.setProperty("webdriver.ie.driver", "res\\IEDriverServer.exe");
    System.setProperty("webdriver.ie.driver.loglevel", "TRACE");
    System.setProperty("webdriver.ie.driver.logfile", "log\\selenium.log");
    DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();        ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
    WebDriver driver = new InternetExplorerDriver(ieCapabilities);
    driver.navigate().to("http://www.google.com");
    //System.out.println(driver.getPageSource());
    driver.findElement(By.id("lst-ib")).sendKeys("selenium");
    driver.findElement(By.name("btnK")).click();

Started InternetExplorerDriver server (64-bit)
2.44.0.0
Listening on port 41180
Log level is set to TRACE
Log file is set to C:\Users\xxxxx\workspace\SeleniumTest\log\selenium.log
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with id == lst-ib (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 342 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: 'xxxxxx', ip: 'xxxxx', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_25'


  • 问题:


    • question:

      它可以在ChromeDriver上运行,我可以在输入字段中输入"selenium"并成功进行搜索,但是为什么InternetExplorerDriver会收到此异常?

      It works on ChromeDriver , I can input "selenium" to input field and serach it successfully , but why InternetExplorerDriver get this Exception ?

      注释:

      有人说,该站点应该位于Windows Server的受信任"位置, 他不确定为什么,但是将google.com添加到Trusted解决了一个问题. 我不知道该方法是否可以解决它,因为我的公司使我无法进行设置.

      Some body said that the site should be in "Trusted" for Windows server installation , he was not sure why, but adding google.com to trusted solved an issue . I don't know whether the way can resolve it , because my company make me impossiable to set it .

      更新1

      我试图在代码中添加wait语句,但是出现以下错误.

      I have tried to add wait statement to my code , but get the below error .

      Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 90 seconds waiting for visibility of element located by By.id: lst-ib Caused by: org.openqa.selenium.NoSuchElementException: Unable to find element with id == lst-ib (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 309 milliseconds

      Exception in thread "main" org.openqa.selenium.TimeoutException: Timed out after 90 seconds waiting for visibility of element located by By.id: lst-ib Caused by: org.openqa.selenium.NoSuchElementException: Unable to find element with id == lst-ib (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 309 milliseconds

      解决方案

      代码现在可以正常工作,最终像这样:

      The code can work now , finally code like this :

                  System.setProperty("webdriver.ie.driver", "res\\IEDriverServer.exe");
                  System.setProperty("webdriver.ie.driver.loglevel", "TRACE");
                  System.setProperty("webdriver.ie.driver.logfile", "log\\selenium.log");
                  DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
               ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
                  WebDriver driver = new InternetExplorerDriver(ieCapabilities);//
                  driver.navigate().to("http://www.google.com");
                  WebElement text =driver.findElement(By.name("q"));
                  text.sendKeys("selenium");
                  text.submit();
      

      我需要告知我已将代码复制到我的同事计算机上以运行它,一开始,我可以成功工作,但我的同事却没有;我们尝试了无数次,得出相同的结果,我们发现IEDriverServer.exe并非每次都关闭,最终他重新启动了计算机,奇怪的是,代码可以成功地工作.我不知道为什么.也许某些环境因素影响了IEDriverServer.exe或其他因素.

      I need to inform that I have copied the code to my colleague computer to run it , In the beginning , I can work successfully ,but my colleague not ; we tried serveral times , come out the same result , we found IEDriverServer.exe didn't be closed ervery time , finally he restarted the computer , So strange , the code can work successfully . I don't know why . Maybe some environment factors affected IEDriverServer.exe or other things. .

      推荐答案

      我很好奇您要在google.com上定位的元素,同样也很好奇Chrome正在使用该定位器定位的元素.当我检查google.com并搜索ID为lst-ib的元素时,没有结果.

      I am curious what element you are trying to locate on google.com and equally curious what element Chrome is locating with that locator. When I check google.com and search for an element with an id of lst-ib there is no result.

      当我选中它时,在Google搜索主页面上输入搜索字段的ID为:id = gbqfq.

      The id for the input search field on the main google search page when I checked it is: id=gbqfq.

      这篇关于Selenium InternetExplorerDriver无法找到明显存在的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆