catherinepanjl 发表于 2017-5-14 17:06:52

求助大神:java selenium运行报错

本帖最后由 catherinepanjl 于 2017-5-14 17:08 编辑

我的selenium版本是3.4.0,我的火狐的版本是:53.0.2,运行脚本的时候报错,请问各位大神有什么解决办法吗?

Exception in thread "main" org.openqa.selenium.InvalidArgumentException: Expected undefined to be a string
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'HP-6450B', ip: '192.168.11.241', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_77'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=d:\temp\rust_mozprofile.4EcdlLaDcOiJ, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0.2, platformVersion=10.0, moz:processID=1968.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}]
Session ID: 2e19fb13-ca1a-4b0b-82a4-0ec9cba27de7
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
      at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
      at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
      at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
      at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:272)
      at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:96)
      at mypro.IdDemo.main(IdDemo.java:15)
代码如下:
package mypro;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class IdDemo {

        public static void main(String[] args) {
                WebDriver driver = new FirefoxDriver();               
                driver.get("http://www.baidu.com");
               
                WebElement searchBox = driver.findElement(By.id("kw"));
                searchBox.sendKeys("test baidu by id");
               
                WebElement searchButton = driver.findElement(By.id("su"));
                searchButton.submit();
               
                driver.close();
        }
}




清晨一缕阳光 发表于 2017-5-14 21:39:08

需要下载火狐浏览器的驱动程序。

catherinepanjl 发表于 2017-5-15 08:08:15

是geckodriver.exe吗?放在跟eclipse.exe同一个路径下面?

catherinepanjl 发表于 2017-5-15 08:17:52

是geckodriver.exe吗?跟eclipse.exe放在同一个路径了

掉渣饼 发表于 2017-5-15 09:15:29

这是因为selenium3引入了driver对Firefox的进行操作,你要先下载个geckodriver,然后在 WebDriver driver = new FirefoxDriver(); 前面加上System.setProperty("webdriver.gecko.driver", "geckodriver.exe的路径");

catherinepanjl 发表于 2017-5-15 10:10:26

我加了这句话:
System.setProperty("webdriver.gecko.driver", "E:\\eclipse-jee-mars-2-win32-x86_64\\eclipse\\geckodriver.exe");
但还是报之前的错
我的geckodriver的 版本是:geckodriver-v0.14.0-win64跟这个有关系吗?

finomy 发表于 2017-5-15 10:30:13

firefox53要用geckodriver0.16和selenium3.4

yuyubill 发表于 2017-5-15 11:52:20

驱动要与浏览器放在一个路径下,找到你的firefox.exe吧,把驱动扔这里

catherinepanjl 发表于 2017-5-15 18:51:59

我把geckodriver0.16的EXE文件放在了firefox。exe一个目录下面,并且在代码中增加了System.setProperty("webdriver.gecko.driver", "geckodriver.exe的路径");这句话
现在程序报另外一个错:
1494845209815        geckodriver        INFO        Listening on 127.0.0.1:41433
1494845210296        geckodriver::marionette        INFO        Starting browser \\?\C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
1494845210761        addons.manager        ERROR        startup failed: "nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"location: "JS frame :: resource://gre/modules/FileUtils.jsm :: FileUtils_getDir :: line 70"data: no] Stack trace: FileUtils_getDir()@resource://gre/modules/FileUtils.jsm:70 < FileUtils_getFile()@resource://gre/modules/FileUtils.jsm:42 < validateBlocklist()@resource://gre/modules/AddonManager.jsm:671 < startup()@resource://gre/modules/AddonManager.jsm:834 < startup()@resource://gre/modules/AddonManager.jsm:3129 < observe()@resource://gre/components/addonManager.js:65
JavaScript error: resource://gre/modules/AddonManager.jsm, line 1657: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
1494845213796        Marionette        INFO        Listening on port 53105
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2570: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
五月 15, 2017 6:46:54 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
信息: Detected dialect: W3C
JavaScript error: resource://gre/modules/FileUtils.jsm, line 70: NS_ERROR_ILLEGAL_VALUE: Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE)

yuyubill 发表于 2017-5-16 14:31:37

catherinepanjl 发表于 2017-5-15 18:51
我把geckodriver0.16的EXE文件放在了firefox。exe一个目录下面,并且在代码中增加了System.setProperty("we ...

加上两句:
System.setProperty("webdriver.gecko.driver","D:\\geckodriver.exe"); System.setProperty("webdriver.firefox.bin","D:\\Firefox\\firefox.exe");

catherinepanjl 发表于 2017-5-16 20:20:58

加了:
System.setProperty("webdriver.gecko.driver", "C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe");
System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); 这两句话,但是还是报错

JavaScript error: resource://gre/modules/AddonManager.jsm, line 1657: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
1494936319519        Marionette        INFO        Listening on port 53878
JavaScript error: resource://gre/modules/AddonManager.jsm, line 2570: NS_ERROR_NOT_INITIALIZED: AddonManager is not initialized
五月 16, 2017 8:05:20 下午 org.openqa.selenium.remote.ProtocolHandshake createSession
页: [1]
查看完整版本: 求助大神:java selenium运行报错