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