[英]How can I choose which firefox executable to use among multiple firefox binaries through Python selenium
I'm using python (v 3.65) selenium (v3.11.0) on Mac OS X (v 10.11.6) with firefox (v 59.0.3) and geckodriver (v 0.20.1). 我在Mac OS X(v 10.11.6)和Firefox(v 59.0.3)和geckodriver(v 0.20.1)上使用python(v 3.65)硒(v3.11.0)。 I have my usual firefox in the Applications folder and a second firefox in another folder.
我在Applications文件夹中有平时的Firefox,在另一个文件夹中有第二个Firefox。 How can I tell python selenium to use the second firefox instead of going to the one in Applications?
如何告诉python selenium使用第二个Firefox,而不是转到“应用程序”中的那个?
I'd prefer an answer that generalises to other browsers besides firefox/geckodriver, if possible. 如果可能的话,我更希望将答案推广到除firefox / geckodriver之外的其他浏览器。
To choose and use one of the Firefox executable among multiple you can use the argument binary_location from firefox.options . 要选择并使用多个Firefox可执行文件之一,可以使用firefox.options中的 binary_location参数。 As an example in the following code block I have used the Firefox Nightly binary to open the Firefox Nightly browser :
作为以下代码块的示例,我使用了Firefox Nightly二进制文件打开Firefox Nightly浏览器:
Code Block : 代码块:
from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options() options.binary_location = r'C:\\Program Files\\Firefox Nightly\\firefox.exe' driver = webdriver.Firefox(firefox_options=options, executable_path=r'C:\\Utility\\BrowserDrivers\\geckodriver.exe') driver.get('http://google.com/') print("Firefox Browser Invoked") driver.quit()
Console Output : 控制台输出:
Firefox Browser Invoked
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.