如何通过Selenium打开Firefox Developer Edition [英] How to open Firefox Developer Edition through Selenium

本文介绍了如何通过Selenium打开Firefox Developer Edition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在有关Selenium的一些教程之后,我安装了geckodriver.为了在python上运行一个简单的代码来运行Selenium,我必须在命令行中指定以下路径:

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

但是我希望Selenium打开我拥有的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 浏览器的常规位置未安装 Firefox开发人员版浏览器.在我的 Windows 8 框中,在目录中安装了 Firefox Developer Edition 浏览器:

C:\Program Files\Firefox Developer Edition

现在,在调用 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
    

  • 浏览器快照:


此用例

在使用 Linux 时,您需要提供以下内容的绝对路径:

  • Firefox开发人员版二进制
  • 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()

Following some tutorials on Selenium, I installed the geckodriver. In order to run a simple code on python to run Selenium, I have to specify this path in the command line:

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

But I want Selenium to open the Developer edition I have as it contains the extension I want to test: When I sepcify the path for the Developer edition executable:

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

Then run my python script:

from selenium import webdriver
browser = webdriver.Firefox()

Selenium still opens the geckodriver browser.

Q: How can I instruct Selenium to run Firefox Dev. Edition in the path I specify?

解决方案

The Firefox Developer Edition browser is not installed at the conventional location where regular Firefox browser gets installed. In my Windows 8 box Firefox Developer Edition browser got installed within the directory:

C:\Program Files\Firefox Developer Edition

Now, while invoking Firefox Developer Edition browser you need to pass the absolute path of the Firefox Developer Edition binary through the argument firefox_binary as follows:

  • Code Block:

    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()
    

  • Console Output:

    Page Title is : Google
    

  • Browser Snapshot:


This usecase

As you are on Linux you need to provide the absolute path of:

  • Firefox Developer Edition binary
  • GeckoDriver binary

So your effective code block will be:

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打开Firefox Developer Edition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆