我刚刚将Python
Selenium
加载到我的Ubuntu
系统中,并按照ReadTheDocs上的入门教程进行操作。当我运行这个程序时:
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()
但是我收到了这个错误:
Traceback (most recent call last):
File "/home/henry/Documents/Scraper/test-selenium.py", line 4, in <module> driver = webdriver.Firefox()
File "/usr/local/lib/python2.7/distpackages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__self.binary, timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__self.binary.launch_browser(self.profile, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser self._wait_until_connectable(timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 108, in _wait_until_connectable % (self.profile.path))
WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmp8xr2V3 If you specified a log_file in the FirefoxBinary constructor, check it for details.
答案 0 :(得分:0)
看起来网络驱动程序存在问题 - 您是否在RasPi上安装了Firefox?
(如果没有,这可能会有所帮助:https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=150438)
答案 1 :(得分:0)
我认为您使用的是selenium 2.53.6
问题是firefox与selenium的兼容性,因为firefox&gt; = 48需要Gecko Driver(https://github.com/mozilla/geckodriver)来在firefox上运行测试用例。或者你可以从这个链接https://ftp.mozilla.org/pub/firefox/releases/46.0.1/
将firefox降级到46 ..