问题
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?
回答1:
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()
回答2:
You can use FirefoxBinary
as described here:
Setting path to firefox binary on windows with selenium webdriver
To set the custom path to Firefox you need to use FirefoxBinary:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('F:\FirefoxPortable\Firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary)
来源:https://stackoverflow.com/questions/54754686/how-to-open-firefox-developer-edition-through-selenium