selenium使用中遇到的問題,轉自:http://blog.csdn.net/funi16/article/details/9036753

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

Build info: version: '2.16.1', revision: '15405', time: '2012-01-05 12:30:12'
解決辦法:

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

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

WebDriver driver = new FirefoxDriver();

 

2、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

暫時還沒解決好。


3、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 下載對應的插件版本,然後修改代碼如下:

[java] view plaincopy
  1. File file = new File("C:/Selenium/iexploredriver.exe");  
  2. System.setProperty("webdriver.ie.driver", file.getAbsolutePath());  
  3. WebDriver driver = new InternetExplorerDriver();  
參考來源:http://stackoverflow.com/questions/10995314/driver-executable-must-be-set-by-the-webdriver-ie-driver-system-property


4、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:這種錯誤真是。。。讓人無語。

 

5、My97DatePicker控件輸入日期問題

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

[java] view plaincopy
  1. driver.findElement(By.id("bookDay")).clear();  
  2.         driver.findElement(By.id("bookDay")).sendKeys("2013-06-17");  

不過我覺得這個方法不好,還在尋找其他辦法。

在網上找了下,有下面這個方法,問題是我看不懂。。。

http://lyh875.blog.163.com/blog/static/21428005820133192552198/

[java] view plaincopy
  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[@οnclick='day_Click(2009,2,2);']");  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章