简体   繁体   English

我如何通过Python Selenium在多个firefox二进制文件中选择要使用的firefox可执行文件

[英]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.

相关问题 如何设置Selenium以使用多个Firefox配置文件? - How can I set up Selenium to use multiple Firefox profiles? 如何使用 GeckoDriver 和 Firefox 到 Python 检测不到 Selenium 脚本? - How can I make a Selenium script undetectable using GeckoDriver and Firefox through Python? python硒选择随机Firefox配置文件 - python selenium choose random firefox profile 在python中,selenium模块。 如何使用firefox驱动程序 - In python, selenium module . how to use firefox driver 如何在Selenium Python中使用Firefox配置文件 - How to use Firefox profiles in Selenium Python 如何使用 Python 退出通过 GeckoDriver 和 Selenium 启动的所有 Firefox 进程 - How to quit all the Firefox processes which gets initiated through GeckoDriver and Selenium using Python 如何用selenium在firefox中禁用javascript? - How can I disable javascript in firefox with selenium? 'geckodriver' 可执行文件需要在 PATH 中使用 GeckoDriver 和 Firefox 到 Selenium - 'geckodriver' executable needs to be in PATH using GeckoDriver and Firefox through Selenium Selenium Firefox Python:我们可以使用下载文件夹的相对路径吗? - Selenium Firefox Python: Can we use relative path for downloads folder? selenium.common.exceptions.WebDriverException:消息:'firefox' 可执行文件需要在 GeckoDriver Firefox Selenium 和 Python 的 PATH 中 - selenium.common.exceptions.WebDriverException: Message: 'firefox' executable needs to be in PATH with GeckoDriver Firefox Selenium and Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM