2012-08-06 55 views
0

可能重复:
How to initialize multiple browsers in WebDriver?如何配置为多个浏览器文件中硒的webdriver

我如何配置文件用于IE和Chrome。 driver = new firefoxDriver();完美工作,但 驱动程序=新的InterExploraDriver或驱动程序=新的C​​hromeDriver无法正常工作。需要IE和Chrome的一些配置。我如何以及在哪里配置? Java中的必要代码是什么?

+0

欢迎来到Stackoverflow。但请在这里与你的老问题很好 - http://stackoverflow.com/questions/11823150/how-to-initialize-multiple-browsers-in-webdriver – 2012-08-06 10:24:05

回答

1

您需要IE和Chrome的独立服务器才能在这些浏览器上运行测试。他们可以在

http://www.seleniumhq.org/download/

https://sites.google.com/a/chromium.org/chromedriver/downloads

下载这些服务器,并将路径的exe文件和初始化驱动程序中找到如下图所示:

IE

System.setProperty("webdriver.ie.driver", pathOftheexe); 
WebDriver driver = new InternetExplorerDriver(); 
driver.get("http://www.google.com"); 

您还需要将每个安全区域的保护模式设置设置为相同的值。在IE上,选择工具菜单,然后点击安全选项卡。对于每个区域,在标签为“启用保护模式”的选项卡底部会出现一个复选框。保持所有区域的设置相同,即ON或OFF。

铬:

System.setProperty("webdriver.chrome.driver", pathOfexe); 
WebDriver driver = new ChromeDriver(); 
driver.get("http://www.google.com"); 

请参考以下链接了解详细信息:

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

+0

我使用IEDriverServer.exe的IE浏览器。我的代码是:File file = new File(“F:\\ Software Download_Ripon \\ WebDriver \\ IEDriverServer_Win32_2.25.2 \\ IEDriverServer.exe”); System.setProperty(“webdriver.ie.driver”,file.getAbsolutePath()); driver = new InternetExplorerDriver(); driver.get( “https://www.google.com/”); IE已打开,但该页面已定向到“http:// localhost:25178 /”,并在页面上显示以下消息“这是WebDriver服务器的初始起始页。” 。谷歌网页未打开 – 2012-08-07 04:05:44

+0

我的Chrome代码运行良好。但是打开一个额外的选项卡,其URL为“http://reganam.ourtoolbar.com/welcome/”。我如何停止打开Reganam标签?只是为了分享我的代码:File file = new File(“F:\\ Software Download_Ripon \\ WebDriver \\ chromedriver_win_22_0_1203_0b \\ chromedriver.exe”); System.setProperty(“webdriver.chrome.driver”,file.getAbsolutePath()); driver = new ChromeDriver(); driver.get(“https://www.google.com/”); – 2012-08-07 04:27:17

0

你可以只使用硒 - 服务器standalone.jar。将它添加到你的类路径中,你不必添加每个浏览器服务器。

相关问题