初学selenium,遇到的问题记录下来。
1、The path to the driverexecutable must be set by thewebdriver.gecko.driver system property
报这个错,是因为你使用了selenium3+Firefox。在selenium3中,使用Firefox,需要添加驱动。
您可以从Github上下载驱动程序下载网址- https://github.com/mozilla/geckodriver/releases/tag/v0.9.0
在代码中加入
System.setProperty("webdriver.firefox.marionette","C:\\ProgramFiles (x86)\\Mozilla Firefox\\geckodriver.exe");
WebDriver driver=newFirefoxDriver();
C:\\Program Files(x86)\\Mozilla Firefox\\geckodriver.exe是驱动放置的位置
2、org.openqa.selenium.firefox.NotConnectedException:Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefoxconsole output:extensions\cpmanager@mozillaonline.com.xpi
原因:Firefox版本与Selenium不兼容。
注意:从下面路径能查看Selenium支持的FireFox版本:
selenium-server-standalone-3.4.0.jar\org\openqa\selenium\firefox\webdriver.xpi\install.rdf
<!-- Firefox -->
<em:targetApplication>
<Description>
<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
<em:minVersion>3.0</em:minVersion>
<em:maxVersion>48.0</em:maxVersion>
</Description>
</em:targetApplication>
最小支持3.0 最大支持48.0
firefox
版本下载地址http://ftp.mozilla.org/pub/firefox/releases/
seleniumjar
包下载地址http://selenium-release.storage.googleapis.com/index.html