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 下载对应的插件版本,而后修改代码以下:
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本身录制的代码,结果回放的时候老是说元素找不到,整的我很头疼,后来发现一个简单的办法,就是直接把值输入日期控件的输入框当中来,
不过我以为这个方法很差,还在寻找其余办法。 在网上找了下,有下面这个方法
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