且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 java selenium 中启动 chromedriver 后更改代理

更新时间:2023-09-18 23:03:04

根据 Selenium 的当前实现,一旦您使用所需的选项功能 配置 WebDriver 实例并初始化WebDriver 会话打开 Web 浏览器,您不能更改功能运行时.即使您能够检索运行时功能,您仍然无法将它们更改回来.

As per Selenium's current implementation once you configure the WebDriver instance with the required Options and Capabilities and initialize the WebDriver session to open a Web Browser, you cannot change the capabilities runtime. Even if you are able to retrieve the runtime capabilities still you won't be able to change them back.

因此,为了使用代理,您必须启动一个新的 WebDriver 会话.

So, in-order to use a proxy you have to initiate a new WebDriver session.

这里是@JimEvans 清晰简洁的评论(截至 2013 年 10 月 24 日 13:02)与代理设置功能相关:

here is @JimEvans clear and concise comment (as of Oct 24 '13 at 13:02) related to proxy settings capability:

当您为任何给定的驱动程序设置代理时,它仅在创建 WebDriver 会话时设置;它不能在运行时更改.即使您获得了所创建会话的功能,您也无法更改它.所以答案是,不,如果你想使用不同的代理设置,你必须开始一个新的会话.

When you set a proxy for any given driver, it is set only at the time WebDriver session is created; it cannot be changed at runtime. Even if you get the capabilities of the created session, you won't be able to change it. So the answer is, no, you must start a new session if you want to use different proxy settings.

您可以在设置功能中找到相关讨论运行 selenium webdriver