【问题标题】:How to disable dns over https in selenium如何在 selenium 中通过 https 禁用 dns
【发布时间】:2021-10-21 09:11:38
【问题描述】:

我正在使用 selenium、java、chrome 编写测试。

如何在 chrome 设置中关闭“dns over https”?

我需要它,因为我的 Intranet DNS 与 Internet 的数据不同。

我已尝试添加以下选项。

    WebDriverManager.chromedriver().setup(); 
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--start-maximized");
    options.addArguments("ignore-certificate-errors");
    options.addArguments("--disable-async-dns");
    options.addArguments("--dns-prefetch-disable");
    options.addArguments("--disable-web-security");
    ChromeDriver driver = new ChromeDriver(options);

它没有帮助。 我什至尝试通过单击设置来更改选项

    driver.get("chrome://settings/security");
    String disableDNSOverHttpsButton = "/html/body/settings-ui//div[2]/settings-main//settings-basic-page//div[1]/settings-section[4]/settings-privacy-page//settings-animated-pages/settings-subpage/settings-security-page//settings-secure-dns//settings-toggle-button//div/cr-toggle";
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(disableDNSOverHttpsButton)));
    driver.findElement(By.xpath(disableDNSOverHttpsButton)).click();

有响应“org.openqa.selenium.NoSuchElementException:”

【问题讨论】:

  • 也许这会有所帮助:stackoverflow.com/questions/33013378/…
  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。
  • 嗨!你找到答案了吗?

标签: selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

解决方法是使用 setExperimentalOption。

    WebDriverManager.chromedriver().setup(); 
    ChromeOptions options = new ChromeOptions();
    Map<String, Object> localState = new HashMap<String, Object>();
    localState.put("dns_over_https.mode", "off");
    localState.put("dns_over_https.templates", "");
    options.setExperimentalOption("localState", localState) ;
    ChromeDriver driver = new ChromeDriver(options);

【讨论】:

    【解决方案2】:
    local_state = {
        "dns_over_https.mode": "off",
        "dns_over_https.templates": "",
    }
    
     
    
    options.add_experimental_option("localState", local_state)
    

    【讨论】:

    • 非常感谢。最后我是这样写的:WebDriverManager.chromedriver().setup(); ChromeOptions options = new ChromeOptions(); Map&lt;String, Object&gt; localState = new HashMap&lt;String, Object&gt;(); localState.put("dns_over_https.mode", "off"); localState.put("dns_over_https.templates", ""); options.setExperimentalOption("localState", localState) ; ChromeDriver driver = new ChromeDriver(options);
    猜你喜欢
    • 1970-01-01
    • 2014-08-26
    • 2020-11-17
    • 2015-08-09
    • 2015-12-16
    • 2012-08-02
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    相关资源
    最近更新 更多