1

I tried to follow an example how to parse websites via python and selenium. But I am running always into the following problem: calling the function webdriver.Firefox opens a firefox instance, but no website via get could be called, it seems: the whole code is blocking in function Firefox (see: print("open call never reached")) The browser is opening and after ca. 30 seconds an exception causes the broswer to exit, with message:

selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpl5dm_azd If you specified a log_file in the FirefoxBinary constructor, check it for details

So what do I am wrong here ? How could I set the profile right ? I tried to set marionette mode True, but got the error : "Unable to find a matching set of capabilities"

from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False

options = Options()
options.log.level = "trace"
options.headless = True

binary = FirefoxBinary("/usr/bin/firefox")
pathDriver = "./geckodriver" 
testUrl="https://duckduckgo.com/"

print("will create firefox instance")
browser = webdriver.Firefox(firefox_binary=binary,options=options,capabilities=cap,executable_path=pathDriver)
print("open call never reached")
browser.get(testUrl)

webdriver.quit()

My test environment:

$ name -a
Linux 5.5.0-0.bpo.2-amd64 #1 SMP Debian 5.5.17-1~bpo10+1 (2020-04-23) x86_64 GNU/Linux

Also I downloaded the latest selenium and the geckodriver here see what versions I do use:

$ python3 –version
Python 3.7.3
$ pip3 freeze | grep sel
selenium==3.141.0
$ geckodriver -V
geckodriver 0.27.0 (7b8c4f32cdde 2020-07-28 18:16 +0000)
$ which firefox 
/usr/bin/firefox
$ firefox -v
Mozilla Firefox 68.10.0esr
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
t2solve
  • 657
  • 4
  • 20

2 Answers2

1

When using GeckoDriver to initiate/spawn a new Browsing Context i.e. Firefox Browser session with Firefox 48+ versions, you have to use Marionette mandatorily.


Solution

The solution would be either to work with default setting of or turn marionette to True as follows:

cap = DesiredCapabilities().FIREFOX
cap["marionette"] = True
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried to set marionette mode True, but got the error : "Unable to find a matching set of capabilities" – t2solve Sep 25 '20 at 10:36
  • @t2solve I'm fine with that error and that can be solved as well. Feel free to raise a new question with your new requirement please. Stackoverflow contributors will be happy to help you out. – undetected Selenium Sep 25 '20 at 10:43
  • I do understand, but actually it's not solving my problem, because at the time my code is not executable, it seems not be "the solution" but I do see the focus is changing somehow – t2solve Sep 25 '20 at 10:55
  • @t2solve To address `Unable to find a matching set of capabilities` see [this](https://stackoverflow.com/questions/44601126/unable-to-find-a-matching-set-of-capabilities-with-selenium-3-4-3-firefox-54-0/44601664#44601664), [this](https://stackoverflow.com/questions/52002958/selenium-common-exceptions-sessionnotcreatedexception-message-unable-to-find-a/52006033#52006033) and [this](https://stackoverflow.com/questions/53953524/selenium-unable-to-find-a-matching-set-of-capabilities-despite-driver-being-in/53953692#53953692) discussion. – undetected Selenium Sep 25 '20 at 12:16
0

you added the parentheses for DesiredCapabilities

cap = DesiredCapabilities.FIREFOX
cap['marionette'] = False 

or you can use webdriver_manager library which will help to get rid of a lot of headaches

pip install webdriver_manager

and use it like this

from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver import DesiredCapabilities

options = webdriver.FirefoxOptions()
options.log.level = "trace"
options.headless = True

capabilities = DesiredCapabilities.FIREFOX
capabilities["marionette"] = False

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install(), options=options)

this setup helps you have the latest browser version for selenium, your error could be caused by the unmatching versions

Alin Stelian
  • 861
  • 1
  • 6
  • 16
  • I change my code and tried without parentheses, but still its the same effect – t2solve Sep 24 '20 at 09:46
  • thanks again, this seems to be a really hand way of getting the driver dependency, but it didn't solved the issue, I also found after 30 seconds a new error message, please see the updatet question – t2solve Sep 24 '20 at 11:48
  • the error is clear, you r pointing the path to firefox instead of gecko driver, also it looks like u r trying to use a profile there, you should update the code question also – Alin Stelian Sep 24 '20 at 11:58
  • check my question, i updated it, with pointing towards the profile problem – t2solve Sep 24 '20 at 13:19