在 java selenium 中启动 chromedriver 后更改代理 [英] Change proxy after starting chromedriver in java selenium

查看:88
本文介绍了在 java selenium 中启动 chromedriver 后更改代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在同一个浏览器上启动chromedriver后是否可以使用代理?

Is it possible to use proxy after starting chromedriver on the same browser?

例如:

  1. 我启动了 chrome 驱动程序
  2. 加载网站
  3. 输入信息
  4. 使用代理
  5. 点击提交

我想我在 python 和 JS 中找到了一些方法,但我不确定如何将它转换为 java

I think i found some ways to do it in python and JS but im not sure how to convert it to java

推荐答案

根据 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

这篇关于在 java selenium 中启动 chromedriver 后更改代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆