【问题标题】:Using IE selenium driver with python在 python 中使用 IE selenium 驱动程序
【发布时间】:2020-08-25 06:54:52
【问题描述】:

我正在尝试定义 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

注意:我使用的是 selenium 4.0.0a1

【问题讨论】:

标签: python selenium internet-explorer selenium-iedriver iedriverserver


【解决方案1】:

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

如果您查看 python selenium 绑定here

您可以看到 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已被弃用,请传入一个Service对象'

因此,不要指定它:-)

你可以试试:

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

【讨论】:

  • 我正在使用 selenium 4.0.0a1,我不明白在哪里可以找到这个版本的 selenium 的 IEdriver。你知道我在哪里可以找到它吗?谢谢!
  • @ניבבדלי 如果您正在使用 python,请使用 pip install selenium。并从 selenium 网站获取您的 ie 驱动程序selenium.dev/downloads
  • @RichEdwards 请访问Selenium Chat Room 并帮助其他用户。
【解决方案2】:

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

所以对于生产环境而不是 Selenium 4.0.0a1 你需要使用 Selenium 3.141.0

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

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

【讨论】:

  • 嗨,这不是问题..我遇到了同样的错误并尝试了两种方法
  • @ניבבדלי 查看更新后的答案,让我知道您对此的看法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-10
  • 1970-01-01
  • 2017-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-09
相关资源
最近更新 更多