-1

我试图定义 IE Web 驱动程序以使用 python,但我有一些我无法理解的错误。也许我必须在 Internet Explorer 上更改一些安全设置?我有interent explorer version 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

注意:我正在使用 selenium 4.0.0a1

4

2 回答 2

0

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

SeleniumPythonAlpha

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

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

driver = webdriver.Ie(executable_path=r'C:\Users\cohe\PycharmProjects\Testing\IEDriverServer.exe')
于 2020-08-25T07:25:21.800 回答
0

您使用的是什么版本的硒?

如果您在这里查看 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 bindings中被移除。

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

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

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

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

因此,不要指定它:-)

你可以试试:

  1. 将您的 IeDriverSerice.exe 位置添加到 PATH 变量。
  2. 将 IeDriverService.exe 文件放在与脚本相同的位置。然后您不必指定它,可以将其保留为默认值
  3. 创建一个服务对象并查看它是否接受二进制路径。
于 2020-08-25T13:56:44.630 回答