英文:
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:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
答案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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论