Selenium webdriver在firefox profile.setpreference中禁用WebRTC检测

时间:2017-02-03 18:06:42

标签: python selenium selenium-webdriver automated-tests

如何在firefox中禁用WebRTC检测 “media.peerconnection.enabled”使用Selenium webdriver

这是代码

 from selenium.webdriver.common.proxy import *
 from selenium import webdriver
 from selenium.webdriver.common.proxy import Proxy, ProxyType
 from time import sleep

profile = webdriver.FirefoxProfile() 
profile.set_preference( "general.useragent.override", tax )
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "xx.xx.xx.xx")
profile.set_preference("network.proxy.http_port", 3128)
profile.set_preference("media.peerconnection.enabled", "false")
profile.update_preferences()
driver = webdriver.Firefox(profile)
driver.implicitly_wait(10)
print "url: "
driver.get('http://www.example.com')

profile.set_preference(“media.peerconnection.enabled”,“false”)仅在我手动设置时不起作用 如何用Selenium

做到这一点

1 个答案:

答案 0 :(得分:0)

我认为你必须按照以下方式使用它:

 from selenium.webdriver.common.proxy import *
 from selenium import webdriver
 from selenium.webdriver.common.proxy import Proxy, ProxyType
 from time import sleep

 # init profile
 profile = webdriver.FirefoxProfile() 

 # set proxy and other prefs.
 profile.set_preference("network.proxy.type", 1)
 profile.set_preference("network.proxy.http", "xx.xx.xx.xx")
 profile.set_preference("network.proxy.http_port", 3128)
 # update to profile. you can do it repeated. FF driver will take it.

 profile.update_preferences()

 # You would also like to block flash 
 profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',False)
 profile.set_preference("media.peerconnection.enabled", False)

 # save to FF profile
 profile.update_preferences()
 driver = webdriver.Firefox(profile)
 driver.get('http://www.google.com')
 :
 :

AFAIK,代码中的问题是,firefox配置文件无法将字符串强制转换为boolean。您尝试设置的这些优先级是布尔值,并且您尝试使用字符串“false”进行设置。 注意False的上限是python中可接受的。您还可以参考Firefox配置文件目录中的prefs.js。它将显示给定firefox实例的所有设置首选项。

还要检查selenium和firefox版本的兼容性。