摸索测试,不管是安装、调测第一个用例都会遇到各种各样的问题,或是自己的问题或是程序本身设置问题
只有把所有问题记录下来,才对得起自己的经历
1、设置firefox的执行文件错误
Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:03:00'
System info: host: 'YangYuchun-PC', ip: '192.168.202.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_171'
Driver info: driver.version: FirefoxDriverat org.openqa.selenium.firefox.internal.Executable.<init>(Executable.java:72)at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:59)at org.openqa.selenium.firefox.FirefoxBinary.<init>(FirefoxBinary.java:55)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)at seleniumTest.FirstSelenium.main(FirstSelenium.java:9)
默认情况下firefox安装路径在c盘不会出现这个问题,如果非C盘或者非默认安装,则需要指定执行文件所在目录,如下:
package seleniumTest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;public class FirstSelenium {public static void main(String args[]){System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe");WebDriver driver = new FirefoxDriver();driver.manage().window().maximize();driver.manage().timeouts().implicitlyWait(8, TimeUnit.SECONDS);driver.get("http://www.baidu.com");driver.quit();}
}
2、selenium版本不配套问题
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
pat@mozilla.org.xpi","e":true,"v":"1.1","st":1496964922348}},"app-global":{"{972ce4c6-7e08-4474-a285-3208198ce6fd}":{"d":"D:\\Program Files\\Mozilla Firefox\\browser\\extensions\\{972ce4c6-7e08-4474-a285-3208198ce6fd}.xpi","e":true,"v":"54.0","st":1496964922230}}}
1532870934632 addons.xpi DEBUG No changes found
1532870934642 addons.xpi DEBUG Registering manifest for D:\Program Files\Mozilla Firefox\browser\features\aushelper@mozilla.org.xpi
1532870934642 addons.xpi DEBUG Loading bootstrap scope from D:\Program Files\Mozilla Firefox\browser\features\aushelper@mozilla.org.xpi
1532870934648 addons.xpi DEBUG Calling bootstrap method startup on aushelper@mozilla.org version 2.0
1532870934650 addons.xpi DEBUG Registering manifest for D:\Program Files\Mozilla Firefox\browser\features\e10srollout@mozilla.org.xpi
1532870934651 addons.xpi DEBUG Loading bootstrap scope from D:\Program Files\Mozilla Firefox\browser\features\e10srollout@mozilla.org.xpi
1532870934654 addons.xpi DEBUG Calling bootstrap method startup on e10srollout@mozilla.org version 1.50
1532870934654 addons.xpi DEBUG Registering manifest for D:\Program Files\Mozilla Firefox\browser\features\firefox@getpocket.com.xpi
1532870934655 addons.xpi DEBUG Loading bootstrap scope from D:\Program Files\Mozilla Firefox\browser\features\firefox@getpocket.com.xpi
1532870934659 addons.xpi DEBUG Calling bootstrap method startup on firefox@getpocket.com version 1.0.5
1532870934669 addons.xpi-utils DEBUG Starting async load of XPI database C:\Users\YANGYU~1\AppData\Local\Temp\anonymous2326053441094436722webdriver-profile\extensions.json
1532870934670 addons.xpi DEBUG Registering manifest for D:\Program Files\Mozilla Firefox\browser\features\screenshots@mozilla.org.xpi
1532870934671 addons.xpi DEBUG Loading bootstrap scope from D:\Program Files\Mozilla Firefox\browser\features\screenshots@mozilla.org.xpi
1532870934674 addons.xpi DEBUG Calling bootstrap method startup on screenshots@mozilla.org version 6.6.0
1532870934674 addons.xpi DEBUG Registering manifest for D:\Program Files\Mozilla Firefox\browser\features\webcompat@mozilla.org.xpi
1532870934675 addons.xpi DEBUG Loading bootstrap scope from D:\Program Files\Mozilla Firefox\browser\features\webcompat@mozilla.org.xpi
1532870934678 addons.xpi DEBUG Calling bootstrap method startup on webcompat@mozilla.org version 1.1
1532870934688 addons.manager DEBUG Registering shutdown blocker for XPIProvider
1532870934689 addons.manager DEBUG Provider finished startup: XPIProvider
1532870934689 addons.manager DEBUG Starting provider: LightweightThemeManager
1532870934689 addons.manager DEBUG Registering shutdown blocker for LightweightThemeManager
1532870934689 addons.manager DEBUG Provider finished startup: LightweightThemeManager
1532870934689 addons.manager DEBUG Starting provider: GMPProvider
1532870934696 addons.manager DEBUG Registering shutdown blocker for GMPProvider
1532870934696 addons.manager DEBUG Provider finished startup: GMPProvider
1532870934696 addons.manager DEBUG Starting provider: PluginProvider
1532870934697 addons.manager DEBUG Registering shutdown blocker for PluginProvider
1532870934697 addons.manager DEBUG Provider finished startup: PluginProvider
1532870934698 addons.manager DEBUG Completed startup sequence
1532870935048 addons.xpi-utils DEBUG Async JSON file read took 0 MS
1532870935049 addons.xpi-utils DEBUG Finished async read of XPI database, parsing...
1532870935052 addons.xpi-utils DEBUG Successfully read XPI database
1532870935065 addons.manager DEBUG Starting provider: <unnamed-provider>
1532870935065 addons.manager DEBUG Registering shutdown blocker for <unnamed-provider>
1532870935065 addons.manager DEBUG Provider finished startup: <unnamed-provider>
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
1532870935179 addons.manager DEBUG Starting provider: PreviousExperimentProvider
1532870935179 addons.manager DEBUG Registering shutdown blocker for PreviousExperimentProvider
1532870935179 addons.manager DEBUG Provider finished startup: PreviousExperimentProviderat org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:118)at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:246)at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:114)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:193)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:182)at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:95)at seleniumTest.FirstSelenium.main(FirstSelenium.java:9)
之前使用python测试时,firefox上selenium版本为3.0.2.0(在菜单-附件组件中查看)
所以需要安装3.0.2.0或者以上版本的java selenium的jar包才可以。重新下载selenium的jar包并重新导入