Selenium:FirefoxProfile异常可以';不要加载配置文件。从PHP调用的Python脚本
我的python脚本包含以下代码:Selenium:FirefoxProfile异常可以';不要加载配置文件。从PHP调用的Python脚本,php,python,bash,selenium-webdriver,selenium-firefoxdriver,Php,Python,Bash,Selenium Webdriver,Selenium Firefoxdriver,我的python脚本包含以下代码: firefox_profile = webdriver.FirefoxProfile() self.driver = webdriver.Firefox(firefox_profile=firefox_profile) 当我从bash执行脚本时,它可以工作,但是如果我从PHP文件调用脚本,则使用以下命令: shell_exec("python path_to_the_script"); 我收到例外情况: selenium.common.exceptions
firefox_profile = webdriver.FirefoxProfile()
self.driver = webdriver.Firefox(firefox_profile=firefox_profile)
当我从bash执行脚本时,它可以工作,但是如果我从PHP文件调用脚本,则使用以下命令:
shell_exec("python path_to_the_script");
我收到例外情况:
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmp7Ob0z6/webdriver-py-profilecopy If you specified a log_file in the FirefoxBinary constructor, check it for details.
我还尝试手动设置配置文件,如下所示:
firefox_profile = webdriver.FirefoxProfile(profile_directory='path_to_the_profile_dir')
firefox_profile = webdriver.FirefoxProfile(profile_directory='path_to_the_profile_dir')
firefox_profile.profile_dir = 'path_to_the_profile_dir'
但是没有发生任何变化,如果我像这样设置概要文件目录路径:
firefox_profile = webdriver.FirefoxProfile(profile_directory='path_to_the_profile_dir')
firefox_profile = webdriver.FirefoxProfile(profile_directory='path_to_the_profile_dir')
firefox_profile.profile_dir = 'path_to_the_profile_dir'
异常错误更改为:
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: path_to_the_profile_dir If you specified a log_file in the FirefoxBinary constructor, check it for details.
我已将所有相关目录的权限设置为777,并尝试覆盖FirefoxBinary.launch_browser
函数,以便它使用更大的超时值,但id无效。
我正在使用Python 2.7、Selenium 2.53.6和Firefox 46.0.1
Firefox正在通过Xvfb和pyvirtualdisplay以无头模式工作。这是因为您已将Firefox更新为selenium不再支持的版本 所以要解决这个问题,你有两个选择
如果您有ubuntu,请遵循以下修复方法:
1.使用“sudo pip安装-U selenium”更新selenium
2.从github下载geckodriver-->
3.解压缩tar.gz文件夹并将gecko可执行文件移动到/usr/local/bin
4.现在打开终端并输入以下命令:
export PATH=$PATH:/usr/local/bin/geckodriver
这应该可以解决问题。。。至少对我有用
我的来源:如果这不能解决您的问题,请检查您的firefox配置文件名 像这样
fp = webdriver.FirefoxProfile('/home/YOUR_USERNAME/.mozilla/firefox/YOUR_PROFILE_NAME.default')
driver = webdriver.Firefox(firefox_profile=fp)
要查找您的firefox配置文件名,请打开文件浏览器并启用“显示隐藏文件”,转到“Home/.mozilla/firefox”,您将看到您的firefox配置文件文件夹
我希望能够解决您的问题根据,Geckodriver v0.19.0推荐Selenium 3.5+(和Firefox 55+),Geckodriver v0.16.0需要Selenium 3.4+,Geckodriver v0.15.0需要Selenium 3.3+。一些发行版在其软件包中仍然使用Selenium的2.x版本(例如Fedora Core 27的python2 Selenium
软件包是2.53.6),因此如果您使用这样的软件包,您可能需要卸载它并改为sudo pip安装Selenium
。