this post was submitted on 07 Jan 2024
6 points (100.0% liked)

Selenium Web Browser Automation

101 readers
4 users here now

Users forum for selenium browser testing. Do not advertise here.

founded 2 years ago
MODERATORS
 
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

options = Options()
options.binary_location = '/mnt/sdb1/firefox/'

driver = webdriver.Firefox(options = options, service=Service(executable_path = '/mnt/sdb1/root'))

driver.get('https://youtube.com')
driver.execute_script('alert(\'your favorite music is here\')')

I get the following error

Traceback (most recent call last):
  File "/mnt/sdb1/root/sele.py", line 8, in 
    driver = webdriver.Firefox(options = options, service=Service(executable_path = '/mnt/sdb1/root'))
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.service.path = DriverFinder.get_path(self.service, options)
  File "/usr/local/lib/python3.9/dist-packages/selenium/webdriver/common/driver_finder.py", line 44, in get_path
    raise NoSuchDriverException(f"Unable to locate or obtain driver for {options.capabilities['browserName']}")
selenium.common.exceptions.NoSuchDriverException: Message: Unable to locate or obtain driver for firefox; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 1 points 11 months ago (1 children)

Honestly while you can use a local driver for selenium your much better off just using one of the docker images here and using a remote connection. If you insist on the local driver then your probably going to want to use a web driver manager to handle that for you so your systems browser doesn’t mess with it.

[–] veekm 1 points 11 months ago* (last edited 11 months ago)

I need to scrape an internal website using the system browser via --marionette Eventually this will be turned into a windows script. I tried using webdriver-manager and got it working but I still need to specify a path to firefox and the site is internal. This is my script in Windows - it doesn't work. It uses GeckDriverManager but I'd prefer a hardcoded path.

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from webdriver_manager.firefox import GeckoDriverManager

options = Options()
options.binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox\firefox.exe')

service = Service(GeckoDriverManager().install(), service_args = ['--marionette-port', '2828', '--connect-existing'] )
driver = webdriver.Firefox(options=options, service = service)
#pageSource = driver.page_source
#print(pageSource)

[–] [email protected] 1 points 8 months ago

Use the full path to the executable and not just the folder it is in?

[–] [email protected] 1 points 11 months ago

I think your options.binary_location needs to point directly to the executable. So: /mnt/sdb1/firefox/firefox

And executable_path should point to your geckodriver: /mnt/sdb1/firefox/geckodriver