接受/忽略Chrome浏览器中的SSL证书

huangapple go评论53阅读模式
英文:

Accept/Ignore SSL certificate in Chrome browser

问题

我在Java中使用ChromeOptions类时遇到了问题。在我的代码中实现它时,它不包含我需要在Chrome浏览器中接受/忽略SSL证书的一些方法,比如.setCapability,这样我就可以传递CapabilityType.ACCEPT_SSL_CERTS, true);

示例:

ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);

...其中setCapability在Eclipse中被标记为错误,并显示以下信息:

The method setCapability(String, boolean) is undefined for the type ChromeOptions
英文:

I am having this problem with ChromeOptions class in Java. When implementing it in my code it doesn't contain some of the methods that I need to Accept/Ignore SSL certificate in Chrome browser. Methods like .setCapability so I can pass in it CapabilityType.ACCEPT_SSL_CERTS, true);.

Example:

ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);    

... where setCapability is being marked as a mistake by Eclipse, and it says

The method setCapability(String, boolean) is undefined for the type ChromeOptions

答案1

得分: 1

我无法在他的帖子中回答,但我认为Nikolai的建议是:

  • 您可以检查此类中是否导入了正确的内容吗?import org.openqa.selenium.remote.CapabilityType;
  • 您在pom.xml文件中使用的Selenium版本是多少?示例:
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
英文:

I can't answer in his thread, but I think Nikolai's suggestion is:

  • can you check you have the correct import in this class? import org.openqa.selenium.remote.CapabilityType;
  • what is the Selenium version you are using in your pom.xml file? Ex:
        &lt;dependency&gt;
            &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
            &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
            &lt;version&gt;3.141.59&lt;/version&gt;
        &lt;/dependency&gt;

答案2

得分: 0

使用Robot类来接受它。对我来说,每次处理这种弹出窗口时都有效。

Robot r = new Robot();
// 使用Tab键移动到所需的按钮
r.keyPress(KeyEvent.VK_TAB);
r.keyRelease(KeyEvent.VK_TAB);

// 然后使用Enter键点击它
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
英文:

Use the Robot class to accept it. For me it works every time I have to deal with this kind of pop-ups.

    Robot r = new Robot();
    // use tab to move to desired button
    r.keyPress(KeyEvent.VK_TAB);
    r.keyRelease(KeyEvent.VK_TAB);

    //than use enter to click it
    r.keyPress(KeyEvent.VK_ENTER);
    r.keyRelease(KeyEvent.VK_ENTER);

huangapple
  • 本文由 发表于 2020年7月28日 20:04:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63133726.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定