当前位置: 首页 > 面试题库 >

Selenium / PhantomJS引发错误

茹高义
2023-03-14
问题内容

我正在尝试在 Python中* 运行 PhantomJS 驱动程序,但出现错误。我读过我应该将整个路径作为参数传递,但这没有帮助。 *

这是代码:

from selenium import webdriver

# driver = webdriver.Chrome('D:\Python_projects\chromedriver_win32/chromedriver.exe') # this works
driver = webdriver.PhantomJS(executable_path='D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')

错误:

Traceback (most recent call last):
  File "path to script", line 8, in <module>
    driver = webdriver.PhantomJS(executable_path='D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')
  File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 50, in __init__
    self.service.start()
  File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 75, in start
    raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver.
Screenshot: available via screen

你知道我在做什么错吗?


问题答案:

用原始字符串创建路径,并添加“ r”:

driver = webdriver.PhantomJS(executable_path=r'D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')


 类似资料:
  • 你知道我做错了什么吗?

  • Selenium Selenium是一个Web的自动化测试工具,最初是为网站自动化测试而开发的,类型像我们玩游戏用的按键精灵,可以按指定的命令自动操作,不同是Selenium 可以直接运行在浏览器上,它支持所有主流的浏览器(包括PhantomJS这些无界面的浏览器)。 Selenium 可以根据我们的指令,让浏览器自动加载页面,获取需要的数据,甚至页面截屏,或者判断网站上某些动作是否发生。 Sel

  • 我的HTML是这样的 组织。openqa。硒。InvalidSelectorException:给定的选择器//输入[@type=checkbox]/以下同级:://td[contains(text(),template]无效或未生成WebElement。出现以下错误:InvalidSelectorError:无法找到xpath表达式为//input[@type=checkbox]/以下同级的元素

  • 我一直在使用C#中的Selenium和PhantomJS,但我希望能够将我的用户代理伪装成这样:

  • 问题内容: 我正在尝试运行此脚本: https://github.com/Chillee/coursera-dl- all 但是,脚本在此行失败,并显示以下错误 如何将phantomjs添加到PATH?我正在运行ubuntu 16.04并通过安装selenium。 问题答案: 我在命令行中使用此命令解决了同样的问题 如果/ home / login / phantomjs / bin是带有可执行文

  • 我正在使用java编写一个带有selenium和phantomjs的自动化程序。起初,我使用firefox进行开发和所有工作。但是,当我将浏览器更改为使用phantomjs时。代码不起作用。在phantomjs中,代码可以帮助用户登录系统,并在登录后页面中单击一个按钮。单击按钮并更改页面后,系统无法在webdriver中获取任何信息(xpath、页面源等)。你能给我一些建议吗?谢谢 Java版本: