Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ubuntu上从python启动selenium_Python_Selenium_Ubuntu - Fatal编程技术网

在ubuntu上从python启动selenium

在ubuntu上从python启动selenium,python,selenium,ubuntu,Python,Selenium,Ubuntu,我有以下脚本 from selenium import webdriver browser = webdriver.Firefox() browser.get('http://localhost:8000') assert 'Django' in browser.title 我得到以下错误 $ python3 functional_tests.py Traceback (most recent call last): File "functional_tests.py", line

我有以下脚本

from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://localhost:8000')

assert 'Django' in browser.title
我得到以下错误

$ python3 functional_tests.py 
Traceback (most recent call last):   File "functional_tests.py", line 3, in <module>
    browser = 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 99, in _wait_until_connectable
    "The browser appears to have exited " selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
$python3功能测试.py
回溯(最近一次调用last):文件“functional_tests.py”,第3行,在
browser=webdriver.Firefox()文件“/usr/local/lib/python3.5/dist-packages/selenium/webdriver/Firefox/webdriver.py”,第80行,在__
self.binary,timeout)文件“/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/extension\u connection.py”,第52行,在__
启动浏览器(self.profile,timeout=timeout)文件“/usr/local/lib/python3.5/dist packages/selenium/webdriver/firefox/firefox\u binary.py”,第68行,在启动浏览器中
self.\u wait\u until\u connectable(timeout=timeout)File“/usr/local/lib/python3.5/dist packages/selenium/webdriver/firefox/firefox\u binary.py”,第99行,在\u wait\u until\u connectable中
“浏览器似乎已退出”selenium.common.exceptions.WebDriverException:消息:在我们可以连接之前,浏览器似乎已退出。如果在FirefoxBinary构造函数中指定了日志文件,请检查它以了解详细信息。
pip3列表
显示
selenium(2.53.6)


firefox-v
显示
Mozilla firefox 47.0

最新版本的firefox不能与selenium一起正常工作。试试46或45

您可以在这里下载:ftp.mozilla.org/pub/firefox/releases

或者
sudo apt get install firefox=45.0.2+build1-0ubuntu1


您还可以通过图形方式执行此操作,如图所示

Firefox的最新版本无法与selenium正常工作。试试46或45

您可以在这里下载:ftp.mozilla.org/pub/firefox/releases

或者
sudo apt get install firefox=45.0.2+build1-0ubuntu1


你也可以像这里所示的那样以图形的方式来做这件事

我也很难解决这个问题,而且我对不得不使用旧版本的Firefox感到不满。这是我使用最新版本Firefox的解决方案。然而,它涉及几个步骤

步骤1。从以下位置下载下一代FirefoxDriver v0.9.0木偶:

步骤2。将文件解压缩到所需文件夹,并将其重命名为“wires”。在我的例子中,我在Documents下创建了一个名为“add_to_system_path”的文件夹。因此,文件位于Documents/add_to_system_path/wires中(同时确保wires文件在其属性下是可执行的)

步骤3。在主文件夹下创建一个名为“.pam\u environment”的文件,然后在其上添加此行并保存

PATH DEFAULT=${PATH}:/absolute/PATH/to/the/folder/where/wires/is/saved

它告诉ubuntu将.pam_环境中的枚举目录添加到系统路径中

步骤4。保存文件,注销用户会话,然后重新登录。这是必要的,以便ubuntu能够识别新添加的系统路径中的文件

步骤5。使用以下代码实例化浏览器实例:

`
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

capabilities = DesiredCapabilities.FIREFOX
capabilities["marionette"] = True
browser = webdriver.Firefox(capabilities=capabilities)
browser.get('http://your-target-url')`

Firefox现在应该可以像往常一样进行实例化了。

我也遇到了这个问题,我对不得不使用旧版本的Firefox感到不满。这是我使用最新版本Firefox的解决方案。然而,它涉及几个步骤

步骤1。从以下位置下载下一代FirefoxDriver v0.9.0木偶:

步骤2。将文件解压缩到所需文件夹,并将其重命名为“wires”。在我的例子中,我在Documents下创建了一个名为“add_to_system_path”的文件夹。因此,文件位于Documents/add_to_system_path/wires中(同时确保wires文件在其属性下是可执行的)

步骤3。在主文件夹下创建一个名为“.pam\u environment”的文件,然后在其上添加此行并保存

PATH DEFAULT=${PATH}:/absolute/PATH/to/the/folder/where/wires/is/saved

它告诉ubuntu将.pam_环境中的枚举目录添加到系统路径中

步骤4。保存文件,注销用户会话,然后重新登录。这是必要的,以便ubuntu能够识别新添加的系统路径中的文件

步骤5。使用以下代码实例化浏览器实例:

`
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

capabilities = DesiredCapabilities.FIREFOX
capabilities["marionette"] = True
browser = webdriver.Firefox(capabilities=capabilities)
browser.get('http://your-target-url')`

Firefox现在应该可以像往常一样实例化了。

听起来像是一个兼容性问题:您安装了哪些Firefox和selenium版本?Firefox的最新版本不能与selenium正常工作。试试46或45。你可以在这里下载
sudo apt get install firefox=45.0.2+build1-0ubuntu1
降级@塔莱斯帕杜阿如果你把它写下来作为一个答案,我会很高兴让它成为正确的答案。@Harrymorno,完成了!=)听起来像是兼容性问题:您安装了什么firefox和selenium版本?firefox的最新版本不能与selenium正常工作。试试46或45。你可以在这里下载
sudo apt get install firefox=45.0.2+build1-0ubuntu1
降级@塔莱斯帕杜阿如果你把它写下来作为一个答案,我会很高兴让它成为正确的答案。@Harrymorno,完成了!=)伟大的故事!谢谢来到这里和大家分享!不客气。希望有些人会觉得这个解决方案很有帮助。这个答案随着selenium 3.x的发布已经过时了。太棒了!谢谢来到这里和大家分享!不客气。希望有些人会觉得这个解决方案很有帮助。随着selenium 3.x的发布,这个答案已经过时了。