【发布时间】:2018-04-23 06:27:05
【问题描述】:
我正在尝试将 PhantomJS 与 Selenium 和 Python 一起使用。
我的理解是:
我将不得不使用 Selenium 包编写 Python 脚本,该包将与 Selenium 交互以在 PhantomJS WebDriver 上运行以自动化 Web 应用程序测试。
我已经安装了以下:
- Python v3.5.1.
- Selenium 使用
pip install seleniumv3.7.0。 - PhantomJS v2.1.1
与此同时,我通过将 Chrome WebDriver 放置在 PATH 中进行了测试,它执行时没有错误。以下是我使用 chrome webdriver 打开 google.com 的脚本。
from selenium import webdriver
driver = webdriver.Chrome() # or add to your PATH
driver.get('https://google.com/')
使用 PhantomJS:
from selenium import webdriver
url = "http://www.google.com"
path_phantom = r'H:\phantomjs\bin\phantomjs.exe'
driver = webdriver.PhantomJS(executable_path=path_phantom)
driver.get(url)
driver.save_screenshot(r'H:\out.png')
driver.quit()
错误:
Traceback(最近一次调用最后一次): 文件“C:\Users\acer\Desktop\testing\openYoutube.py”,第 5 行,在 驱动程序 = webdriver.PhantomJS() 文件“C:\Users\acer\AppData\Local\Programs\Python\Python35-32\lib\site-package s\selenium\webdriver\phantomjs\webdriver.py",第 51 行,在 init 中 log_path=service_log_path) 文件“C:\Users\acer\AppData\Local\Programs\Python\Python35-32\lib\site-package s\selenium\webdriver\phantomjs\service.py",第 50 行,在 init 中 service.Service.init(self, executable_path, port=port, log_file=open(log _path, 'w')) PermissionError: [Errno 13] Permission denied: 'ghostdriver.log'
我是否放错了 PhantomJS exe 或缺少任何步骤?
【问题讨论】:
-
将它放在任何地方,但只需确保它在环境路径中可用并且您会收到权限错误,因此无论它在哪里出现,它都无法创建日志文件我建议将它放在这样的目录中不需要管理员权限的地方
标签: python-3.x selenium webdriver phantomjs