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

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

问题描述

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

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

EX:

  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

推荐答案

按照

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 清晰简洁的评论(截至13年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天全站免登陆