如何使用FirefoxProfile

时间:2017-04-12 18:08:22

标签: java selenium webdriver selenium-firefoxdriver firefox-driver

我需要一种自动方式在Firefox Selenium webdriver中启用Flash而无需用户交互。

我试过了:

FirefoxProfile profile = new FirefoxProfile();
//As 0 is to disable, I used 1. I don"t know what to use.
profile.setPreference("plugin.state.flash", 1);
WebDriver driver = new FirefoxDriver(profile);

但这仍然需要我点击"允许"。

This is shown all the time, even with the code above

2 个答案:

答案 0 :(得分:4)

这对我没用: profile.setPreference("plugin.state.flash", 2);

相反,我用过: def urlparse(urlColumnElem): try: #default timeout is 8 seconds. conn = urllib.request.urlopen(urlColumnElem,timeout=8) redirect=conn.geturl() #check redirect if(redirect == urlColumnElem): #print ("same: ") #print(redirect) return (redirect) else: #print("Not the same url ") return(redirect) #catch all the exceptions except urllib.error.HTTPError as e: return (e.code) except urllib.error.URLError as e: return ('URL_Error') except socket.timeout as e: return ("timeout") except http.client.HTTPException as e: return("HTTPException")

我认为" 2"也会激活插件。

答案 1 :(得分:1)

我自己找到了解决方案。

This Post Shows how to disable Adobe flash Player in Python

要在" JAVA"中启用它,只需将false更改为true。

profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so","true");

它有效:)