如何在运行时更改 Firefox Web 驱动程序代理设置? [英] How to change Firefox web driver proxy settings at runtime?

查看:19
本文介绍了如何在运行时更改 Firefox Web 驱动程序代理设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Selenium 2.35.0 并配置代理设置,例如:

I use Selenium 2.35.0 and configure proxy settings like:

DesiredCapabilities cap = new DesiredCapabilities();
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(proxyStr).setFtpProxy(proxyStr).setSslProxy(proxyStr);
cap.setCapability(CapabilityType.PROXY, proxy);

driver = new FirefoxDriver(firefox, profile, cap);

当我需要更改代理设置时,我会强制重新启动 webdriver 并指定其他proxyStr".

When I need to change proxy settings I force to restart webdriver and speify other "proxyStr".

如何在不重启 webdriver 的情况下实现此更改?

How I can reach this changing without of webdriver restart?

推荐答案

当您为任何给定的驱动程序设置代理时,它仅在创建 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.

这篇关于如何在运行时更改 Firefox Web 驱动程序代理设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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