There are some details.

有一些细节。

  • code:

    代码:

        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();
    

- console ouput:

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:

    问题:

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

    它在ChromeDriver上工作,我可以输入“selenium”来输入字段,并成功地将其serach,但是为什么InternetExplorerDriver会得到这个异常?

  • note:

    注意:

    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 .

    一些机构表示,该网站应该在“可信”的Windows服务器安装上,他不知道为什么,但将google.com添加到可信的解决了一个问题。我不知道该怎么解决,因为我的公司让我无法设置。

  • update1

    update1

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

    我已经尝试将wait语句添加到代码中,但是得到以下错误。

    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

    在线程“main”org.openqa.selenium中异常。TimeoutException:在90秒后超时,等待由其定位的元素的可见性。id: lst-ib由:org.openqa.selenium引起。NoSuchElementException:无法找到id == lst-ib的元素(警告:服务器没有提供任何stacktrace信息)命令持续时间或超时:309毫秒

  • solution

    解决方案

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();

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. .

我需要通知的是,我已经将代码复制到我的同事电脑上运行,一开始我可以顺利工作,但是我的同事没有;我们试了好几次,结果都一样,我们找到了IEDriverServer。exe并不是每次都关闭,最后他重新启动了计算机,如此奇怪,代码可以成功工作。我不知道为什么。可能是一些环境因素影响了IEDriverServer。exe或其他东西。

3 个解决方案

#1


1

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。com上找到什么元素,同样也很好奇Chrome用这个定位器找到了什么元素。当我检查google。com并搜索id为lst-ib的元素时,没有结果。

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

当我检查时,主谷歌搜索页面上输入搜索字段的id为:id=gbqfq。

更多相关文章

  1. 我的构建可以规定我的代码覆盖范围永远不会变得更糟吗?
  2. java中循环遍历删除List和Set集合中元素的方法
  3. 使用SAX Filter将新元素插入XML文件
  4. 如何判断用户的java代码是否已成功编译?
  5. 如何获得嵌入式Jetty Web服务器来转储其JSP的临时Java代码
  6. 急求用jersey2.x+spring3.x 开发rest webservice Java代码实例
  7. “java.exe”已退出,代码为 1。
  8. Java 编程下的同步代码块(售票员)
  9. JAVA 关于图片上传的代码

随机推荐

  1. css工具提示提示 - 顶部不起作用
  2. Webkit之理解HTML解析和DOM树
  3. HTML5实现图片预览功能
  4. “div > p”和“div p”是一样的吗?
  5. Jquery - 表单验证,为错误消息添加css样
  6. 里面的获得蓝色边框
  7. 使用hexo+github免费搭建个人博客网站超
  8. 利用HTML5的window.postMessage实现跨域
  9. Html5 Canvas+Javascript实现一个简单画
  10. 在同一个类中添加值并返回总和