2012-08-06 53 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。將它添加到你的類路徑中,你不必添加每個瀏覽器服務器。

相關問題