繁体   English   中英

在 python 中使用 IE selenium 驱动程序

[英]Using IE selenium driver with python

我试图定义 IE Web 驱动程序以使用 python,但我有一些我无法理解的错误。 可能我必须在 Internet Explorer 中更改一些安全设置? 我有 Internet Explorer 版本 11,谢谢。

from selenium import webdriver

driver = webdriver.Ie(executable_path=r"C:\Users\cohe\PycharmProjects\Testing\IEDriverServer.exe")

i got some errors:

Traceback (most recent call last):
  File "C:/Users/cohe/PycharmProjects/Testing/Shrepoint.py", line 3, in <module>
    driver = webdriver.Ie(executable_path=r"C:\Users\cohe\PycharmProjects\Testing\IEDriverServer.exe")
  File "C:\Users\cohe\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\ie\webdriver.py", line 54, in __init__
    warnings.warn('executable_path has been deprecated, please pass in a Service object',
NameError: name 'warnings' is not defined

注意:我使用的是硒 4.0.0a1

不清楚您使用的是哪个版本的Selenium 客户端。 但是, Selenium Python客户端的最新稳定版本是v3.141.0

SeleniumPythonAlpha

因此,对于生产环境而不是Selenium 4.0.0a1,您需要使用Selenium 3.141.0

此外,当您使用原始开关即r ,您需要使用单引号而不是双引号。 实际上,您的代码行将是:

driver = webdriver.Ie(executable_path=r'C:\Users\cohe\PycharmProjects\Testing\IEDriverServer.exe')

你用的是什么版本的硒?

如果您在此处查看 python selenium 绑定:

您可以看到 2 个关键部分:

 - executable_path - Deprecated: path to the executable. If the default is used it assumes the executable is in the $PATH

if executable_path != 'IEDriverServer.exe':
            warnings.warn('executable_path has been deprecated, please pass in a Service object',
                          DeprecationWarning, stacklevel=2)

这些在selenium 4 alpha 1 绑定中被删除了。

您的第一个也是最好的选择:

假设您拥有最新的 v4 selenium - 这是在 alpha 测试中,可能会进一步频繁更改。 除非您需要尖端功能,否则您可能希望将您的版本回滚到最新的稳定版。 那应该再次允许可执行路径。

下一个选项:错误/警告仅在您尝试指定路径时才会抛出。 线索在你的错误中:

'executable_path 已被弃用,请传入一个 Service 对象'

因此,不要指定它:-)

你可以试试:

  1. 将您的 IeDriverSerice.exe 位置添加到 PATH 变量。
  2. 将 IeDriverService.exe 文件放在与脚本相同的位置。 那么您不必指定它,可以将其保留为默认值
  3. 创建一个服务对象,看看它是否接受二进制路径。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM