selenium安装栏"importfirefoxdriver"

Ran*_*ram 6 java selenium selenium-webdriver

我正在尝试使用eclipse下载selenium web驱动程序,我正在最后一步并成功导入Web驱动程序,但是,当我尝试为firefox执行相同操作时,我没有获得导入选项.有什么建议?下面的代码有什么问题吗?

码:

package webdriver_project;

import org.openqa.selenium.WebDriver;

public class webdriver_module_1 {
    public static void main(String[] args) {
        WebDriver driver = new firefoxDriver();
    }

}
Run Code Online (Sandbox Code Playgroud)

kro*_*lko 2

如果您使用的是 Firefox 48 或更高版本,则必须首先下载 Marionette 驱动程序:
https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
选择适合您系统的版本(windows/ Linux,32 或 64 位),下载它并更新 Path 系统变量以添加可执行文件的完整目录路径。
请参阅更改日志中的官方信息:https://github.com/SeleniumHQ/selenium/blob/master/dotnet/CHANGELOG

Geckodriver 现在是 Firefox 自动化的默认机制。这是 Mozilla 对该浏览器的驱动程序的实现,并且是 Firefox 版本 48 及更高版本自动化所必需的。


我不知道如何使用 eclipse 下载 selenium。您是否从他们的页面下载了库(jar)并使用Java Build Path/Libraries选项将它们作为外部 jar 手动放置在 Eclipse 中?

无论如何,我认为最简单的方法是将项目转换为 Maven 项目:

我的示例项目中的全部内容pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>WebKierowca</groupId>
    <artifactId>WebKierowca</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

最后创建下面的java类,更改指向Marionette驱动程序(geckodriver.exe)的路径,右键单击该类并将其作为Java应用程序运行。如果一切正常,它应该启动 Firefox,转到 google 网页,搜索单词“selenium”并显示搜索结果 5 秒钟:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Test {

    public static void main(String ... x){
        // Path to Marionette driver
        System.setProperty("webdriver.gecko.driver", "C:/serwery/geckodriver.exe");

        WebDriver driver = new FirefoxDriver();

        driver.get("http://www.google.com");

        driver.findElement(By.name("q")).sendKeys("Selenium");
        driver.findElement(By.name("btnG")).click();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        driver.quit();
    }
}
Run Code Online (Sandbox Code Playgroud)