【问题标题】:Python script in selenium硒中的Python脚本
【发布时间】:2017-06-03 13:34:00
【问题描述】:

我是 selenium 和 python 的新手。

我已从 selenium IDE 导出脚本,当我尝试在 python 中执行脚本时,我收到如下错误,

EException AttributeError: "'Service' object has no attribute 'log_file'" in <bo
und method Service.__del__ of <selenium.webdriver.firefox.service.Service object
 at 0x0000000002AA4550>> ignored
======================================================================
ERROR: test_sharepoint_python (__main__.SharepointPython)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\scripts\sharepoint python1.py", line 12, in setUp
    self.driver = webdriver.Firefox()
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 139, in __init__
    self.service = Service(executable_path, log_path=log_path)
  File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\service.py", li
ne 45, in __init__
    log_file = open(log_path, "a+")
IOError: [Errno 13] Permission denied: 'geckodriver.log'
----------------------------------------------------------------------
Ran 1 test in 0.030s
FAILED (errors=1)

请指导我如何解决这个问题。已经看到其他帖子提到更新 geckodriver 的路径。如果这样可以解决问题,请告诉我在哪里可以找到 geckodriver。但是我无法在任何地方查看 geckodriver.log 尝试下载和安装 geckodriver 但 exe 没有执行

【问题讨论】:

标签: python selenium


【解决方案1】:

有错误:权限被拒绝:'geckodriver.log'

  1. 尝试通过locate geckodriver.log查找“geckodriver.log”

  2. chmod 777 geckodriver.log

【讨论】:

  • 这不是一个好主意。仅仅通过将所有权利交给每个人来解决文件的“权限被拒绝”问题几乎不是一个安全的解决方案。
  • 我已经预料到了这个答案,但测试可以提供帮助。如果它与链接的答案相同,则根本无济于事。
  • 我在windows机器上使用它。
  • 即使在对 geckodriver.log 提供完全控制之后,我仍然看到同样的错误。
  • 在我的机器路径 geckodriver.log 位于 c:\python27\。请告诉我这是正确的路径
【解决方案2】:

遇到同样的问题,发现这个:https://github.com/SeleniumHQ/selenium/issues/3128

使用他们提出的使用 python 脚本中指定的 log_path 构建 webdriver 的解决方法对我来说已经解决了问题。 解决方法的详细信息是:

  1. 确保操作系统包含在其中
  2. 在声明中:self.driver = webdriver.Firefox() 改为:self.driver = webdriver.Firefox(log_path = os.devnull)

好消息是帖子说这是一个错误,已在更新的版本中得到纠正。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 2015-07-05
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多