Selenium問題總結

1.Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: XP。html

咱們只要在WebDriver driver = new FirefoxDriver(); 前面指定咱們瀏覽器的具體信息便可:java

System.setProperty ( "webdriver.firefox.bin" , "E:/Program Files/Mozilla Firefox/firefox.exe" );git

WebDriver driver = new FirefoxDriver();github

 

2. java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, seehttps://github.com/mozilla/geckodriver.
web

緣由是使用了最新的selenium webdriver版本Selenium 3.x,此版本不支持直接啓動firefox,必需要先設置SystemProperty
chrome

下載最新版本的geckoDriver https://github.com/mozilla/geckodriver/releasesapache

System.setProperty("webdriver.gecko.driver", "E:/AndroidWorkspace/SeleniumTest/geckodriver-v0.19.1-win64/geckodriver.exe");api

 

3.Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, seehttp://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded fromhttp://code.google.com/p/chromedriver/downloads/list
 at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
 at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105)
 at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:75)
 at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:107)
 at com.example.tests.Selenium2ForChrome.main(Selenium2ForChrome.java:18)
瀏覽器

出現這個錯誤的緣由是由於谷歌瀏覽器和selenium不是原生的,須要在谷哥里面裝插件,插件下載地址是http://code.google.com/p/chromedriver/downloads/list安全

 

4.WebDriver driver = new FirefoxDriver();時總是編譯出錯:FirefoxDriver cannot be resolved to a type。

試過不少方法都不行,最後把eclipse版本更新後就正常了。

相似的不少問題可能都跟編譯器有關係,因此儘可能保持用最新的編譯器。

 

5.The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://code.google.com/p/selenium/downloads/list 

該問題的錯誤緣由和上面的同樣,用IEdriver的時候也須要裝插件,去http://code.google.com/p/selenium/downloads/list 下載對應的插件版本,而後修改代碼以下:

    1. File file = new File("C:/Selenium/iexploredriver.exe");  
    2. System.setProperty("webdriver.ie.driver", file.getAbsolutePath());  
    3. WebDriver driver = new InternetExplorerDriver(); 

 

6.Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 119%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 5.98 seconds

錯誤緣由:IE瀏覽器的比例調大了,按ctrl+0,能夠恢復原來的大小,便可。PS:這種錯誤真是。。。讓人無語。

 

7.My97DatePicker控件輸入日期問題

以前用的是seleniumIDE本身錄製的代碼,結果回放的時候老是說元素找不到,整的我很頭疼,後來發現一個簡單的辦法,就是直接把值輸入日期控件的輸入框當中來,

    1. driver.findElement(By.id("bookDay")).clear();  
    2. driver.findElement(By.id("bookDay")).sendKeys("2013-06-17"); 

不過我以爲這個方法很差,還在尋找其餘辦法。 在網上找了下,有下面這個方法

    1. selenium.selectFrame("relative=up");  
    2.   //點擊日期文本框  
    3.   selenium.click("days");  
    4.   //必須增長Thread.sleep(),不增長會報錯,提示找不到下一條命令中的元素  
    5.   //另,嘗試使用waitForPageToLoad代替,會超時出錯;  
    6.   Thread.sleep(5000);  
    7.   //當前爲4月,向前移兩個月  
    8.   selenium.click("//div[@id='dpTitle']/div[2]");  
    9.   selenium.click("//div[@id='dpTitle']/div[2]");  
    10.   //點擊2009-02-02  
    11.   selenium.click("//td[@onclick='day_Click(2009,2,2);']");

 

 8.baiduInputText.sendKeys("sdfs");總是編譯出錯:The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)。

寫成這樣就能夠了:baiduInputText.sendKeys(new String[] {"sdfs"});

 

9.Driver info: driver.version: FirefoxDriver
    at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:116)
    at java.util.Optional.orElseGet(Unknown Source)
    at org.openqa.selenium.firefox.FirefoxOptions.getBinary(FirefoxOptions.java:218)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:155)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:120)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:98)
    at com.hejing.selenium.Selenium2.main(Selenium2.java:24)

報這個錯誤一樣是由於firefox的安裝路徑與默認安裝路徑不一致所致,不一致狀況都須要單獨進行設置firefox的安裝路徑:System.setProperty("webdriver.firefox.bin", "D:/software/Mozilla Firefox/firefox.exe");

 

10.Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:754)

意思是咱們缺乏了設置ie瀏覽器的驅動,下載ie的驅動而後再配置到工程中便可。

System.setProperty("webdriver.ie.driver", "E:/Java workspace/SeleniumTest/IEDriverServer_x64_3.8.0/IEDriverServer.exe");

 

11.Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for

不能建立session會話異常,在啓動ie瀏覽器的時候錯誤:全部區域的保護模式設置不一致。

而後就去查閱了文檔:https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver

說的是:在Windows Vista或Windows 7上的IE 7或更高版本上,必須將每一個區域的保護模式設置設置爲相同的值。 值能夠打開或關閉,只要每一個區域相同。 要設置保護模式設置,請從工具菜單中選擇「Internet選項...」,而後單擊安全選項卡。 對於每一個區域,在標籤爲「啓用保護模式」的標籤底部將出現一個複選框。
另外,對於IE 10及更高版本,必須禁用「加強保護模式」。 此選項位於「Internet選項」對話框的「高級」選項卡中。

按照說明操做果真能正常運行了。

 

12.Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4444 [/127.0.0.1] failed: Connection refused: connect
Caused by: java.net.ConnectException: Connection refused: connect

異常緣由是沒有啓動遠程服務器,客戶端與服務端無法創建鏈接。

運行遠程服務器:java -jar E:\selenium-server-standalone-3.8.1.jar

相關文章
相關標籤/搜索