代码之家  ›  专栏  ›  技术社区  ›  PlanetAtkinson

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

  •  -1
  • PlanetAtkinson  · 技术社区  · 7 年前

    我正在Mac OS X(V10.11.6)上使用python(v3.65)selenium(v3.11.0),firefox(V59.0.3)和geckodriver(V0.20.1)。我的常用firefox位于应用程序文件夹中,另一个firefox位于另一个文件夹中。我如何告诉python selenium使用第二个firefox而不是应用程序中的firefox?

    如果可能的话,我更喜欢一个可以推广到除firefox/geckodriver之外的其他浏览器的答案。

    1 回复  |  直到 7 年前
        1
  •  0
  •   undetected Selenium    7 年前

    选择并使用 Firefox 可在多个文件中执行您可以使用参数 二进制\u位置 从…起 firefox。选项 .在下面的代码块中,我使用了 Firefox每晚 二进制打开 Firefox每晚 浏览器:

    • 代码块:

      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()
      
    • 控制台输出:

      Firefox Browser Invoked