selenium - 如何通过Selenium打开Firefox Developer Edition

标签 selenium selenium-webdriver geckodriver selenium-firefoxdriver firefox-developer-edition

根据一些关于 Selenium 的教程,我安装了 geckodriver。为了在 python 上运行一个简单的代码来运行 Selenium,我必须在命令行中指定这个路径:

export PATH=$PATH:/home/xx/Downloads/geckodriver-v0.24.0-linux64

但我希望 Selenium 打开我拥有的 Developer 版本,因为它包含我想要测试的扩展: 当我为 Developer Edition 可执行文件指定路径时:

export PATH=$PATH:/home/xx/Documents/ff_extension/firefox/

然后运行我的 python 脚本:

from selenium import webdriver
browser = webdriver.Firefox()

Selenium 仍会打开 geckodriver 浏览器。

问:如何指示 Selenium 运行 Firefox Dev。我指定的路径中的版本?

最佳答案

Firefox Developer Edition 浏览器未安装在安装常规 Firefox 浏览器的常规位置。在我的 Windows 8 框中,Firefox Developer Edition 浏览器安装在目录中:

C:\Program Files\Firefox Developer Edition

现在,在调用 Firefox Developer Edition 浏览器时,您需要通过参数 firefox_binary如下:

  • 代码块:

    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    
    firefox_dev_binary = FirefoxBinary(r'C:\Program Files\Firefox Developer Edition\firefox.exe')
    driver = webdriver.Firefox(firefox_binary=firefox_dev_binary, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
    driver.get('https://www.google.co.in')
    print("Page Title is : %s" %driver.title)
    # driver.quit()
    
  • 控制台输出:

    Page Title is : Google
    
  • 浏览器快照:

Firefox-DeveloperEdition


这个用例

因为您在 Linux 上,您需要提供以下的绝对路径:

  • Firefox Developer Edition 二进制
  • GeckoDriver 二进制

因此您的有效代码块将是:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

firefox_dev_binary = FirefoxBinary('/path/to/Firefox Developer Edition/firefox')
driver = webdriver.Firefox(firefox_binary=firefox_dev_binary, executable_path='/home/xx/Downloads/geckodriver-v0.24.0-linux64/geckodriver')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
# driver.quit()

关于selenium - 如何通过Selenium打开Firefox Developer Edition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54754686/

相关文章:

java - Selenium - 跳过一张 table

java - Selenium 'browserName was not a boolean' InvalidArgumentException,无法解决

java - selenium 3.3.1 中的 Actions 类已弃用,使用 contextClick 寻找解决方案

selenium - 如何使用 Selenium 和 Python 或 Perl 查找事件元素的相邻元素

c# - 如何检查我的每个循环中是否存在元素

java - Selenium Web Driver - 如何在后台运行 Firefox

python - 连接中止错误 : [WinError 10053] An established connection was aborted by the software in your host machine with GeckoDriver and Firefox

python - 无法从 PyCharm python 控制台正确运行 Firefox (geckodriver)

java - 爬虫获取外部网站搜索结果

java - 如何在网页未完全加载时强制WebDriver执行命令?