【问题标题】:disable notification for allowing my location using selenium禁用通知以允许使用 selenium 进行我的位置
【发布时间】:2018-06-17 15:13:30
【问题描述】:

我正在尝试初始化 FirefoxDriver,以便它可以禁用网站通知以允许我的位置。 我搜索并找到了这段代码。但是当将 ffprofile 放在 FirefoxDriver() 上时,它说无法解析构造函数。

System.setProperty(Utility.MOZILLA_DRIVER, Utility.MOZILLA_PATH);
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference("javascript.enabled", false);
driver = new FirefoxDriver(ffprofile);
driver.manage().window().maximize();

实用类在这里:

 public class Utility { 
    public static final String MOZILLA_PATH="C:\\SeleniumDrivers\\firefox\\geckodriver.exe"‌​; 
    public static final String MOZILLA_DRIVER="webdriver.gecko.driver"; 
    }

运行的时候报错是这样的:

Error:(16, 18) java: no suitable constructor found for FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile)
constructor org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver(org.openqa.selenium.Capabilities) is not applicable
(argument mismatch; org.openqa.selenium.firefox.FirefoxProfile cannot be converted to org.openqa.selenium.Capabilities)
constructor org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver(org.openqa.selenium.firefox.FirefoxOptions) is not applicable
(argument mismatch; org.openqa.selenium.firefox.FirefoxProfile cannot be converted to org.openqa.selenium.firefox.FirefoxOptions)
constructor org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver(org.openqa.selenium.firefox.GeckoDriverService) is not applicable
(argument mismatch; org.openqa.selenium.firefox.FirefoxProfile cannot be converted to org.openqa.selenium.firefox.GeckoDriverService)
constructor org.openqa.selenium.firefox.FirefoxDriver.FirefoxDriver(org.openqa.selenium.firefox.XpiDriverService) is not applicable
(argument mismatch; org.openqa.selenium.firefox.FirefoxProfile cannot be converted to org.openqa.selenium.firefox.XpiDriverService)

【问题讨论】:

  • 告诉我们什么是Utility.MOZILLA_DRIVERUtility.MOZILLA_PATH
  • public class Utility { public static final String MOZILLA_PATH="C:\\SeleniumDrivers\\firefox\\geckodriver.exe";公共静态最终字符串 MOZILLA_DRIVER="webdriver.gecko.driver"; }
  • 用这些信息更新问题not as cmets

标签: java selenium selenium-webdriver mutablecapabilities


【解决方案1】:

在使用 Selenium 3.8.1 时,您可以使用扩展 org.openqa.selenium.MutableCapabilitiesFirefoxOptions 类来使用 FirefoxProfile,如下所示:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;

public class FirefoxProfile_new {

    public static void main(String[] args) {

        System.setProperty(Utility.MOZILLA_DRIVER, Utility.MOZILLA_PATH);
        FirefoxOptions options = new FirefoxOptions();
        options.setProfile(new FirefoxProfile());
        WebDriver driver = new FirefoxDriver(options);
        driver.get("https://www.google.com");
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2016-03-24
    • 2021-08-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多