简体   繁体   English

如何从Watir-Webdriver更改Opera的代理设置?

[英]How to change Opera's proxy settings from Watir-Webdriver?

(This question is loosely related to my previous question ) (此问题与我先前的问题大致相关)

Hello there. 你好。

I have been using Watir-Webdriver with Mozilla FireFox for a week now, and I am quite pleased with it. 我已经在Mozilla FireFox中使用Watir-Webdriver了一个星期,对此我感到非常满意。 However, since I am making a test wich tries to connect to some websites multiple times using different proxies, I found that using FireFox was extremely slow. 但是,由于我正在尝试使用不同的代理多次尝试连接到某些网站,因此我发现使用FireFox的速度非常慢。 Firefox's starting time is (at least on my computer) about 15 seconds(if you're lucky) so I am looking to find something to speed the thing up. Firefox的启动时间(至少在我的计算机上)约为15秒(如果您很幸运的话),因此我希望找到可以加快运行速度的方法。 This made me look into other browsers and their start up times. 这使我了解了其他浏览器及其启动时间。 It seems Opera is quite fast. 看来Opera很快。 However, since it is 'new' in Selenium Webdriver and thus also in Watir-webdriver there is not much documentation about it. 但是,由于它是Selenium Webdriver中的“新功能”,因此在Watir-webdriver中也是“新功能”,因此没有太多文档。

Enough talking, time for the question: 足够多的谈话,是时候提问了:

How can I, using watir-webdriver(or Selenium-webdriver directly), change the proxy that Opera uses for connections? 如何使用watir-webdriver(或直接使用Selenium-webdriver)更改Opera用于连接的代理?

I'm not quite sure I understand the use case, but as a hack/workaround you can change any Opera setting from OperaWatir by loading opera:config and running JS in it to set preferences. 我不太确定我能理解用例,但是作为破解/解决方法,您可以通过加载Opera:config并在其中运行JS来设置首选项,从而从OperaWatir更改任何Opera设置。 In other words, 换一种说法,

browser.goto('opera:config')
browser.execute_script( 'opera.setPreference("Proxy", "HTTP Server", "127.0.0.1:8888")' )
browser.execute_script( 'opera.setPreference("Proxy", "Use HTTP", "1")' )

should work without restart or anything. 应该可以正常工作而无需重新启动或执行任何操作。 The opera:config page itself shows you the options you can set. Opera:config页面本身会向您显示可以设置的选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM