Selenium WebDriver and InternetExplorer

痞子三分冷 提交于 2019-12-12 08:55:05

问题


I've recently updated to Selenium 2.24.1 to get Firefox 13 working. With this update you are now to run an executable similar to chromedriver.exe for it to dispatch events to IE. However I have had no luck in getting tests to run with IE. For this to run with chrome I obviously have to set the webdriver.chrome.driver bit as well, but things work fine in it and Firefox with the same code.

Here is my source code:

public class GoogleTest {

@Test
public void test() throws Exception {
  System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
  final WebDriver driver = new InternetExplorerDriver();
  driver.get("http://www.google.com");
  driver.findElement(By.name("q")).sendKeys("test");
  driver.findElement(By.name("q")).submit();
  driver.quit();
}

}

However I am greeted with this stack trace upon execution of this test

org.openqa.selenium.NoSuchElementException: Unable to find element with name == q (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 395 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 15:28:49'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_01'
Driver info: driver.version: RemoteWebDriver
Session ID: e20f8370-00ed-4bf6-a4fa-a0c09c2b6d8c
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:472)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:303)
at org.openqa.selenium.By$ByName.findElement(By.java:291)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:234)

回答1:


This is probably really obvious, but as you didn't mention it in your original post and you just downloaded the driver and your internal toy app is working, have you double-checked the security settings in IE as mentioned on the IEDriver code page:

On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".

If you were using a previous version of Selenium before, you've likely already done this, but I figured it was worth checking just to be sure...




回答2:


Well, the error message is misleading at least it was in my case. I had a system that was locked down by system administrator with Protected Mode: Off. So I wasn't able to switch the Protected mode. Then I realized that the system had an admin user, so logged in as admin user and tried to switch the Protected Mode. It was still disabled. Then I run Selenium under the admin user account and things worked just fine.

So you may need to login with admin privileges to be able to run selenium. That trick worked for me.




回答3:


Use the below code

System.setProperty("webdriver.ie.driver", "E:\\Selenium\\workspace\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();



回答4:


Check the IEWebdriver server that you downloaded. If you are using 32bit IE, download and use the 32bit IEWebdriver.

Hope that helps.




回答5:


I was having very similar issues. There was a setting in Internet Options that needed to be turned on in order to make it work. Advanced > Settings > Security > Allow active content to run in files on My Computer.

Once I checked this box, my IE tests worked as expected and could find elements and interact with the browser.



来源:https://stackoverflow.com/questions/11157902/selenium-webdriver-and-internetexplorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!