【问题标题】:How to set Chrome Options when using WebDriverManager?使用 WebDriverManager 时如何设置 Chrome 选项?
【发布时间】:2019-12-23 07:42:06
【问题描述】:

我正在使用 Web 驱动程序管理器来设置 chrome 驱动程序。在设置驱动程序时,我想添加一些 chrome 选项?在使用 Web 驱动程序管理器时该怎么做?

我检查了 WebDriverManager API,但找不到任何线索..

【问题讨论】:

  • 欢迎来到 StackOverflow。对于这样的问题,展示您尝试过的和没有奏效的内容非常有用。你能分享你到目前为止所尝试的吗? (分享你的代码)

标签: java automated-tests selenium-chromedriver webdrivermanager-java


【解决方案1】:
public void WebDriverManagerTest()
{
    //setup the chromedriver using WebDriverManager
    WebDriverManager.chromedriver().setup();

    //Create Chrome Options
    ChromeOptions option = new ChromeOptions();
    option.addArguments("--test-type");
    option.addArguments("--disable-popup-bloacking");
    DesiredCapabilities chrome = DesiredCapabilities.chrome();
    chrome.setJavascriptEnabled(true);
    option.setCapability(ChromeOptions.CAPABILITY, option);

    //Create driver object for Chrome
    WebDriver driver = new ChromeDriver(option);

    //Navigate to a URL
    driver.get("http://toolsqa.com");

    //quit the browser
    driver.quit();
}

找到答案..检查上面!

【讨论】:

  • 使用上面的代码但它不起作用 public class TestLogin{ @BeforeTest public void Setup() { WebDriverManager.chromedriver().setup(); DesiredCapabilities chrome = DesiredCapabilities.chrome(); // 错误 * 此行有多个标记 - DesiredCapabilities 无法解析 - * DesiredCapabilities 无法解析为类型 */ chrome.setJavascriptEnabled(true); chrome.setCapability(ChromeOptions.CAPABILITY, 选项); WebDriver driver = new ChromeDriver(option); // 错误:类型不匹配:无法从 ChromeDriver 转换为 WebDriver}
  • DesiredCapabilities chrome = DesiredCapabilities.chrome(); // 错误 * 此行有多个标记 - DesiredCapabilities 无法解析 - * DesiredCapabilities 无法解析为类型 */
  • WebDriver driver = new ChromeDriver(option); // 错误:类型不匹配:无法从 ChromeDriver 转换为 WebDriver}
【解决方案2】:

这是示例代码:

public class Test1{
    
    @Test
    public void WebDriverManagerTest()
    {
        //setup the chromedriver using WebDriverManager
        WebDriverManager.chromedriver().setup();
        //Create driver object for Chrome
        WebDriver driver = new ChromeDriver();
        //Navigate to a URL
        driver.get("http://toolsqa.com");
        //quit the browser
        driver.quit();
    }
}

【讨论】:

    【解决方案3】:

    来自https://pypi.org/project/webdriver-manager/,在.install()之后传入

    from selenium import webdriver
    from webdriver_manager.opera import OperaDriverManager
    
    options = webdriver.ChromeOptions()
    options.add_argument('allow-elevated-browser')
    options.binary_location = "C:\\Users\\USERNAME\\FOLDERLOCATION\\Opera\\VERSION\\opera.exe"
    
    driver = webdriver.Opera(executable_path=OperaDriverManager().install(), options=options)
    

    【讨论】:

      猜你喜欢
      • 2022-01-15
      • 1970-01-01
      • 2013-03-27
      • 2019-04-12
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 2018-03-16
      • 2017-12-01
      相关资源
      最近更新 更多