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。

我们只要在WebDriver driver = new FirefoxDriver(); 前面指定我们浏览器的具体信息即可:

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

WebDriver driver = new FirefoxDriver();

 

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.

原因是使用了最新的selenium webdriver版本Selenium 3.x,此版本不支持直接启动firefox,必须要先设置SystemProperty

下载最新版本的geckoDriver https://github.com/mozilla/geckodriver/releases

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

 

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

 

posted on 2017-12-16 15:21  red_rose  阅读(777)  评论(0编辑  收藏  举报