Selenium WebDriver和InternetExplorer [英] Selenium WebDriver and InternetExplorer

查看:124
本文介绍了Selenium WebDriver和InternetExplorer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新到Selenium 2.24.1,以使Firefox 13能够正常工作.通过此更新,您现在将运行类似于chromedriver.exe的可执行文件,以将事件调度到IE.但是,我没有运气能与IE一起运行测试.为了与chrome一起运行,我显然也必须设置webdriver.chrome.driver位,但是在使用相同代码的Firefox和Firefox中,一切正常.

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.

这是我的源代码:

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)

推荐答案

这可能确实很明显,但是由于您没有在原始帖子中提及它,而您刚刚下载了驱动程序,并且内部玩具应用程序正在运行,所以您仔细检查了IEDriver代码页上提到的IE中的安全设置:

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:

在Windows Vista或Windows 7的IE 7或更高版本上,必须将每个区域的保护模式设置设为相同的值.该值可以打开或关闭,只要每个区域都相同即可.要设置保护模式设置,请从工具"菜单中选择"Internet选项...",然后单击安全性"选项卡.对于每个区域,选项卡底部都会有一个标记为启用保护模式"的复选框.

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

如果您以前使用过早期版本的Selenium,您可能已经做到了,但是我认为值得检查一下……

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

这篇关于Selenium WebDriver和InternetExplorer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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