硒 2 铬驱动程序

发布于 2024-12-05 04:32:22 字数 1255 浏览 1 评论 0原文

因此,我已阅读有关将 chromedriver 添加到我的路径的所有文档并遵循所有文档。我使用的是带有 selenium2、maven、eclipse 和所有最新驱动程序的 Mac:

Error:
The path to the chromedriver executable must be set by the webdriver.chrome.driver system property;

我将 chromedriver 放在“应用程序”文件夹中,我的路径如下所示:

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:

我缺少什么?我根本无法使用 chrome 驱动程序运行。任何帮助都会很棒我现在正在尝试随机的东西。

这是我关于 selenium 的 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>

So I have read all the docs on adding chromedriver to my path and followed all of them. I am on a Mac with selenium2, maven, eclipse, and all the latest drivers:

Error:
The path to the chromedriver executable must be set by the webdriver.chrome.driver system property;

I put chromedriver in my Applications folder and my path looks like:

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:

What am I missing? I cannot run with chrome driver at all. Any help would be great I'm trying random stuff now.

Here is my pom section on selenium:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

洒一地阳光 2024-12-12 04:32:23

我不确定 Maven,但这就是我设置属性 webdriver.chrome.driver 的方式

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

I am not sure about Maven but this how I set the property webdriver.chrome.driver

System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
望笑 2024-12-12 04:32:23

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

  1. systemPropertyVariables 配置添加到 maven- pom.xml 中的surefire-plugin。这(通常)是因为 surefire 是测试的调用者,也是系统属性设置的地方。

    <插件>;
        maven-surefire-plugin;
        <版本>2.7.1
        <配置>
            <系统属性变量>
                ${webdriver.chrome}
            
        
    
    
  2. 现在在某处定义${webdriver.chrome}。一个好的开始是 pom.xml

    中的 部分

    ;
        /home/gede/bin/chromedriver
    
    

通过使用 可能可以更好地完成此操作就像 Simon Martinelli 的 示例

Setting the webdriver.chrome.driver system property via maven can be done by the following (and tested working):

  1. Add systemPropertyVariables configuration to the maven-surefire-plugin in your pom.xml. This is (typically) because surefire is the caller for tests and where system properties will be set.

    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.7.1</version>
        <configuration>
            <systemPropertyVariables>
                <webdriver.chrome.driver>${webdriver.chrome}</webdriver.chrome.driver>
            </systemPropertyVariables>
        </configuration>
    </plugin>
    
  2. Now define ${webdriver.chrome} somewhere. A good start is a <properties> section in your pom.xml

    <properties>
        <webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome>
    </properties>
    

Potentially this could be done better via the use of <profiles> like in Simon Martinelli's example

吐个泡泡 2024-12-12 04:32:23

您可以尝试使用驱动程序二进制下载器 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>

这将下载二进制文件并设置一个 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>

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

You could have a go at using the driver binary downloader maven plugin to download the driver binaries for you (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>

This will download the binaries and set a maven property that you can use in your surefire/failsafe configuration like this:

                <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>

When you instantiate a new driver object the system property pointing to the driver binary location will now be set and it will just work.

神爱温柔 2024-12-12 04:32:23

所以在pom中你必须像这样设置它

                  <dependency>
                  <groupId>org.seleniumhq.selenium</groupId>
                  <artifactId>selenium-chrome-driver</artifactId>
                  <version>2.34.0</version>
                  </dependency>

这是一个使用selenium运行chrome的java代码

        System.setProperty("webdriver.chrome.driver","C:/chromedriver.exe");
        WebDriver myD = new ChromeDriver();

为了让你运行chrome你需要从这里下载chrome驱动程序。 https://code.google.com/p/chromedriver/downloads/list

完成后,您必须将其设置在环境变量中。阅读此https://code.google.com/p/selenium/wiki/ChromeDriver

谢谢,

       Mediha

So in the pom you have to set it like this

                  <dependency>
                  <groupId>org.seleniumhq.selenium</groupId>
                  <artifactId>selenium-chrome-driver</artifactId>
                  <version>2.34.0</version>
                  </dependency>

This is a java code to run the chrome using selenium

        System.setProperty("webdriver.chrome.driver","C:/chromedriver.exe");
        WebDriver myD = new ChromeDriver();

In order for you to run Chrome you need to download the chrome driver from here. https://code.google.com/p/chromedriver/downloads/list

Once you have done that then you have to set it in environment variable. Read this https://code.google.com/p/selenium/wiki/ChromeDriver

Thanks,

       Mediha
最单纯的乌龟 2024-12-12 04:32:23
System.setproperty("webdriver.chrome.driver","your file path here with chromedriver.exe");
webDriver driver=new chromeDriver();
driver.get("http://google.com");
System.setproperty("webdriver.chrome.driver","your file path here with chromedriver.exe");
webDriver driver=new chromeDriver();
driver.get("http://google.com");
断爱 2024-12-12 04:32:23

试试这个:

System.setProperty("webdriver.chrome.driver","/location to/chromedriver folder");
WebDriver driver = new ChromeDriver();
driver.get("your.app");

Try this:

System.setProperty("webdriver.chrome.driver","/location to/chromedriver folder");
WebDriver driver = new ChromeDriver();
driver.get("your.app");
無處可尋 2024-12-12 04:32:23

它适用于我,无需设置 webdriver.chrome.driver 属性。只需将 chromedriver 添加到 PATH

> echo $PATH
/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin
>    
> which chromedriver
/usr/local/bin/chromedriver

如果您使用 Homebrew,安装 chromedriver 并添加到 PATH 就可以像这样简单地完成:

brew install chromedriver

有用的链接:

https://sites.google.com/a/chromium.org/chromedriver/

http://brewformulas.org/Chromedriver

It works for me without setting webdriver.chrome.driver property. Just by adding chromedriver to PATH

> echo $PATH
/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin
>    
> which chromedriver
/usr/local/bin/chromedriver

If you use Homebrew, installing chromedriver along with adding to PATH can be done as simple as this:

brew install chromedriver

Useful links:

https://sites.google.com/a/chromium.org/chromedriver/

http://brewformulas.org/Chromedriver

昨迟人 2024-12-12 04:32:23

只需在您的 Maven pom 中添加 WebDriverManager,如果您的浏览器设置为默认配置,它无需手动设置即可工作。

Just add WebDriverManager in your maven pom and it works without manual setup if you have your browser setup in default config.

彩扇题诗 2024-12-12 04:32:23
    Pom.xml code and Selenium code below:


   <groupId>com.HelloWorld</groupId>
   <artifactId>t</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>t</name>
   <url>http://maven.apache.org</url>

   <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>




     <webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome>

     </properties>

     <build>
     <resources>
        <resource>
            <directory>src/main/java/resources</directory>
            <filtering>true</filtering> 
        </resource>
      </resources>
      <plugins>

      <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.7.1</version>
       <configuration>
        <systemPropertyVariables>
            <webdriver.chrome.driver>${webdriver.chrome}
       </webdriver.chrome.driver>
        </systemPropertyVariables>
      </configuration>
       </plugin>


      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
        </plugin>

      </plugins>


       </build>
       <dependencies>

       <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
      </dependency>

      <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-
     chrome-driver -->
     <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>3.8.1</version>
    </dependency>



       <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.4.0</version>
      </dependency>  
      <dependency>
     <groupId>org.testng</groupId>
     <artifactId>testng</artifactId>
      <version>6.8</version>
     <scope>test</scope>
     </dependency>

     <dependency>   
            <groupId>org.seleniumhq.selenium</groupId>   
            <artifactId>selenium-chrome-driver</artifactId>   
            <version>3.8.1</version>   
        </dependency>   

        <dependency>
       <groupId>io.github.bonigarcia</groupId>
       <artifactId>webdrivermanager</artifactId>
      <version>2.1.0</version>
      </dependency>



      <dependency>
      <groupId>com.relevantcodes</groupId>
      <artifactId>extentreports</artifactId>
     <version>2.41.2</version>
     </dependency>



      <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.8.2</version>
      </dependency>
      <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.8.2</version>
      </dependency>
     </dependencies>
</project>


 Selenuim Code 

public class App 
{
static String currentDir = System.getProperty("user.dir");
static WebDriver driver;

   @BeforeClass
    public static void setupClass() {
        ChromeDriverManager.getInstance().setup();
        driver= new ChromeDriver();
        driver.get("https://www.google.com/");
    }


@Test
    public void test() {





    System.out.println( "Hello World!" );

    }
  }
    Pom.xml code and Selenium code below:


   <groupId>com.HelloWorld</groupId>
   <artifactId>t</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>t</name>
   <url>http://maven.apache.org</url>

   <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>




     <webdriver.chrome>/home/gede/bin/chromedriver</webdriver.chrome>

     </properties>

     <build>
     <resources>
        <resource>
            <directory>src/main/java/resources</directory>
            <filtering>true</filtering> 
        </resource>
      </resources>
      <plugins>

      <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.7.1</version>
       <configuration>
        <systemPropertyVariables>
            <webdriver.chrome.driver>${webdriver.chrome}
       </webdriver.chrome.driver>
        </systemPropertyVariables>
      </configuration>
       </plugin>


      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
        </plugin>

      </plugins>


       </build>
       <dependencies>

       <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
      </dependency>

      <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-
     chrome-driver -->
     <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-chrome-driver</artifactId>
    <version>3.8.1</version>
    </dependency>



       <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.4.0</version>
      </dependency>  
      <dependency>
     <groupId>org.testng</groupId>
     <artifactId>testng</artifactId>
      <version>6.8</version>
     <scope>test</scope>
     </dependency>

     <dependency>   
            <groupId>org.seleniumhq.selenium</groupId>   
            <artifactId>selenium-chrome-driver</artifactId>   
            <version>3.8.1</version>   
        </dependency>   

        <dependency>
       <groupId>io.github.bonigarcia</groupId>
       <artifactId>webdrivermanager</artifactId>
      <version>2.1.0</version>
      </dependency>



      <dependency>
      <groupId>com.relevantcodes</groupId>
      <artifactId>extentreports</artifactId>
     <version>2.41.2</version>
     </dependency>



      <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.8.2</version>
      </dependency>
      <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.8.2</version>
      </dependency>
     </dependencies>
</project>


 Selenuim Code 

public class App 
{
static String currentDir = System.getProperty("user.dir");
static WebDriver driver;

   @BeforeClass
    public static void setupClass() {
        ChromeDriverManager.getInstance().setup();
        driver= new ChromeDriver();
        driver.get("https://www.google.com/");
    }


@Test
    public void test() {





    System.out.println( "Hello World!" );

    }
  }
墨落画卷 2024-12-12 04:32:22

WebDriverManager 添加到您的项目中:

<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
    <version>5.1.0</version>
</dependency>

此库下载您需要的最新版本的 WebDriver 二进制文件并导出正确的 Java系统变量(webdriver.chrome.driverwebdriver.gecko.driverwebdriver.opera.driverwebdriver.edge.driverwebdriver.ie.driver),只需分别使用以下句子之一:

WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.iedriver().setup();

有关 https://bonigarcia.dev/webdrivermanager/

Add WebDriverManager to your project:

<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
    <version>5.1.0</version>
</dependency>

This library downloads the latest version of the WebDriver binary you need and export the proper Java system variable (webdriver.chrome.driver, webdriver.gecko.driver, webdriver.opera.driver, webdriver.edge.driver, webdriver.ie.driver), simply using one of the following sentences respectively:

WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.edgedriver().setup();
WebDriverManager.iedriver().setup();

More info on https://bonigarcia.dev/webdrivermanager/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文