Firefox blank webbrowser with selenium

When I call a firefox webbrowser with python firefox webdriver, the firefox is opening with a blank page (nothing in the navigation barre), wait and close.

The python consol give me this error :

Traceback (most recent call last): File "firefox_selenium2.py", line 4, in driver = webdriver.Firefox() File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 80, in init self.binary, timeout) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in init self.binary.launch_browser(self.profile, timeout=timeout) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser self._wait_until_connectable(timeout=timeout) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 108, in _wait_until_connectable % (self.profile.path)) selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmpngm7g76x If you specified a log_file in the FirefoxBinary constructor, check it for details.

My code is the exemple from the python selenium read_the_doc : from selenium import webdriver from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

Any help would be appreciated

PS : firefox version 49 selenium version 2.53.6 python 3.5


According to this post https://github.com/SeleniumHQ/selenium/issues/2739#issuecomment-249479530 the is that you need to use something called Gecko Driver, found here https://github.com/mozilla/geckodriver. Other people have had success going back to a previous version (before 48) of Firefox as well. I'm also experiencing this problem and don't actually understand how to do either solution and am making slow progress.

Hi Dennis, I'll post my step by step solution now that I got it to work.

Step By Step solution

The problem is that Selenium and Firefox don't support one another anymore. I don't actually understand why but hopefully someone can comment and explain in more thorough detail than I. There are two possible solutions. One is install something called Geckodriver. I got that installed but had difficulty adding it to my PATH and generally found myself frustrated.

Instead I went a simpler route. First I uninstalled firefox with the command

sudo apt-get purge firefox

Then I downloaded Firefox 47.0.1 from here (I selected the english US version). I then moved it from my downloads folder to my home folder. Then I extracted it using this command.

tar xjf firefox-47.0.1.tar.bz2

Your number Firefox may be different from mine. Then I cd'd into that directory

cd firefox    

which brought me into that directory. Then all that was left was to run the command

sudo apt install firefox 

After which the version of Selenium I have worked again. Happily I'm back to writing code not configuring things!

链接地址: http://www.djcxy.com/p/62756.html

上一篇: php selenium webdriver在centos7.2上运行firefox

下一篇: 带有硒的Firefox空白网页浏览器