【问题标题】:Having issues with firefox driver or chrome driver for selenium硒的 Firefox 驱动程序或 chrome 驱动程序存在问题
【发布时间】:2017-03-20 08:02:03
【问题描述】:

例如,当我的 chrome 放在命令提示符中时,它会给我路径 - /Applications/Google\ Chrome.app

我设置了

System.setProperty("webdriver.chrome.driver", "/Applications/Google/Chrome.app"); WebDriver 驱动程序 = new ChromeDriver();
driver.get("http://www.google.com");

但它不起作用,与Firefox相同。我使用了很多已经给出的建议,但似乎没有一个有效。有人可以告诉我是否有什么要补充的吗?

【问题讨论】:

    标签: java selenium browser


    【解决方案1】:

    您为什么使用“/Applications/Google/Chrome.app”。您只需要提供驱动程序的路径,而不是浏览器。以下是 Firefox 的代码,但您需要下载和配置 GeckoDriver(最新版本的 FF 和 Selenium 3.x)

    public class FirefoxTest {
    
    @Test
    public void FirefoxTest_Test1() {
        System.setProperty("webdriver.gecko.driver","D:\\Firefox\\geckodriver.exe");
        FirefoxDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");
    }
    }
    

    查看此链接以获取使用 Firefox 下载和设置 Geckodriver 的完整详细信息 - http://automationtestinghub.com/selenium-3-0-launch-firefox-with-geckodriver/

    【讨论】:

      【解决方案2】:

      使用 chrome 驱动程序最简单的方法是.. 下载驱动程序并将其放入项目的 bin 文件夹中。无需设置驱动位置的路径

      【讨论】:

        【解决方案3】:

        对于 Chrome:需要从 http://chromedriver.storage.googleapis.com/index.html?path=2.24/ 下载新的 Chrome 驱动程序 并提及 chomedriver.exe 的本地系统路径

        System.setProperty("webdriver.chrome.driver","G:\\ravik\\Ravi-Training\\Selenium\\Drivers\\cd\\chromedriver.exe");
            DesiredCapabilities capabilities = DesiredCapabilities.chrome();
            ChromeDriver d1 = new ChromeDriver(capabilities);
        

        对于 FF:如果您的 Firefox 版本是最新的(46.0 或更高版本),则使用 geckodriver 以及 selenium 2.53.0 jar 文件。下载 geckodriver 表单https://github.com/mozilla/geckodriver/releases,然后将其保存为本地系统中的“电线”。提及到电线的本地系统路径。

        System.setProperty("webdriver.gecko.driver", "G:\\ravik\\Ravi-Training\\Selenium\\Marionette for firefox\\wires.exe");
            WebDriver driver = new MarionetteDriver();
        

        希望这会有所帮助。

        【讨论】:

          猜你喜欢
          • 2021-05-14
          • 1970-01-01
          • 2015-09-21
          • 1970-01-01
          • 2016-06-30
          • 2021-11-01
          • 1970-01-01
          • 1970-01-01
          • 2017-09-11
          相关资源
          最近更新 更多