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

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

Accept/Ignore SSL certificate in Chrome browser

问题

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

示例:

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

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

  1. 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:

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

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

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

答案1

得分: 1

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

  • 您可以检查此类中是否导入了正确的内容吗?import org.openqa.selenium.remote.CapabilityType;
  • 您在pom.xml文件中使用的Selenium版本是多少?示例:
  1. <dependency>
  2. <groupId>org.seleniumhq.selenium</groupId>
  3. <artifactId>selenium-java</artifactId>
  4. <version>3.141.59</version>
  5. </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:
  1. &lt;dependency&gt;
  2. &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
  3. &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
  4. &lt;version&gt;3.141.59&lt;/version&gt;
  5. &lt;/dependency&gt;

答案2

得分: 0

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

  1. Robot r = new Robot();
  2. // 使用Tab键移动到所需的按钮
  3. r.keyPress(KeyEvent.VK_TAB);
  4. r.keyRelease(KeyEvent.VK_TAB);
  5. // 然后使用Enter键点击它
  6. r.keyPress(KeyEvent.VK_ENTER);
  7. 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.

  1. Robot r = new Robot();
  2. // use tab to move to desired button
  3. r.keyPress(KeyEvent.VK_TAB);
  4. r.keyRelease(KeyEvent.VK_TAB);
  5. //than use enter to click it
  6. r.keyPress(KeyEvent.VK_ENTER);
  7. 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:

确定