硒2铬驱动器

duc*_*212 19 selenium webdriver maven selenium-webdriver

所以我已经阅读了关于将chromedriver添加到我的路径中的所有文档,并遵循了所有这些文档.我在使用selenium2,maven,eclipse以及所有最新驱动程序的Mac上:

Error:
The path to the chromedriver executable must be set by the webdriver.chrome.driver system property;
Run Code Online (Sandbox Code Playgroud)

我把chromedriver放在我的Applications文件夹中,我的路径如下:

echo $PATH  
/Users/tcerrato/selenium/BS_Sel_Project/auto_helper/test_scripts:/usr/local/apache-maven-2.2.1//bin:/Users/oracle/oracle/product/10.2.0/db_1/bin:/opt/local/bin:/opt/local/sbin:/Applications:
Run Code Online (Sandbox Code Playgroud)

我错过了什么?我根本无法使用Chrome驱动程序.任何帮助都会很棒我现在正在尝试随机的东西.

这是我关于硒的pom部分:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium</artifactId>
    <version>2.0rc2</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>2.6.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

Bon*_*cía 31

将此依赖项添加到项目中:

<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
    <version>3.7.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

这个库下载最新的版本中,你需要和导出正确的Java系统变量(webdriver的二进制的webdriver.chrome.driver,webdriver.gecko.driver,webdriver.opera.driver,phantomjs.binary.path,webdriver.edge.driver,webdriver.ie.driver),只是分别使用下面的句子之一:

WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.phantomjs().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.iedriver().setup();
Run Code Online (Sandbox Code Playgroud)

有关https://github.com/bonigarcia/webdrivermanager的更多信息


nil*_*esh 21

我不确定Maven,但这是我如何设置属性webdriver.chrome.driver

System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
Run Code Online (Sandbox Code Playgroud)

  • 怎么会在python中这样做? (2认同)

小智 10

webdriver.chrome.driver通过maven 设置系统属性可以通过以下方式完成(并进行测试工作):

  1. 添加systemPropertyVariables配置到maven-surefire-plugin您的pom.xml.这是(通常)因为surefire是测试的调用者以及将设置系统属性的位置.

    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.7.1</version>
        <configuration>
            <systemPropertyVariables>
                <webdriver.chrome.driver>${webdriver.chrome}</webdriver.chrome.driver>
            </systemPropertyVariables>
        </configuration>
    </plugin>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 现在定义${webdriver.chrome}某个地方.一个好的开始是<properties>你的一个部分pom.xml

    <properties>
        <webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome>
    </properties>
    
    Run Code Online (Sandbox Code Playgroud)

可能通过使用<profiles>Simon Martinelli的例子可以做得更好


Ard*_*sco 6

您可以使用驱动程序二进制下载程序maven插件为您下载驱动程序二进制文件(https://github.com/Ardesco/selenium-standalone-server-plugin):

                <plugin>
                    <groupId>com.lazerycode.selenium</groupId>
                    <artifactId>driver-binary-downloader-maven-plugin</artifactId>
                    <version>1.0.7</version>
                    <configuration>
                        <rootStandaloneServerDirectory>${project.basedir}/src/test/resources/selenium_standalone_binaries</rootStandaloneServerDirectory>
                        <downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips</downloadedZipFileDirectory>                            
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>selenium</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
Run Code Online (Sandbox Code Playgroud)

这将下载二进制文件并设置maven属性,您可以在surefire/failsafe配置中使用,如下所示:

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.7.2</version>
                    <configuration>                            
                        <systemProperties>                              
                            <!--Set properties passed in by the driver binary downloader-->
                            <phantomjs.binary.path>${phantomjs.binary.path}</phantomjs.binary.path>
                            <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                            <webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver>
                            <webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver>
                        </systemProperties>
                        <includes>
                            <include>**/*WebDriver.java</include>
                        </includes>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
Run Code Online (Sandbox Code Playgroud)

当您实例化一个新的驱动程序对象时,现在将设置指向驱动程序二进制位置的系统属性,它将正常工作.