【问题标题】:Python Selenium Internet Explorer scripts don't workPython Selenium Internet Explorer 脚本不工作
【发布时间】:2022-11-18 01:50:22
【问题描述】:

如果我制作一个像这样的简单脚本:

from selenium import webdriver
from selenium.webdriver.ie.service import Service
import os
from pathlib import Path

path = Path().absolute()
path = os.path.join(path, 'IEDriverServer')
driver = webdriver.Ie(executable_path=path)
driver.get('https://www.google.com/')
print("ANYTHINGGG")

Selenium 在 IE 模式下打开 Edge(没问题),打开 google,但之后它停止了……不要打印“ANYTHINGGG”并且我无法在 driver.get('https://www.google.com/') 之后编写任何程序。

这个问题似乎在任何网站。

任何人都知道什么可以解决这个问题?

(我使用的是 windows 10,python 3.7.9)

只希望代码不会在driver.get('https://www.google.com/') 上停止

【问题讨论】:

  • 只发生在 IE 上?
  • 是的,chrome 工作正常,但我的工作需要 IE ..

标签: python selenium internet-explorer


【解决方案1】:

如果你想用 IEDriver 自动化 Edge IE 模式,你需要:

  1. 使用指向 Microsoft Edge 浏览器的附加属性定义 InternetExplorerOptions
  2. 启动一个InternetExplorerDriver的实例并传递给它InternetExplorerOptions。 IEDriver 启动 Microsoft Edge,然后在 IE 模式下加载您的 Web 内容。

    您还需要满足Required Configuration。关于在Edge中使用Internet Explorer Driver自动化IE模式的详细信息,可以参考this doc

    你的代码好像不对,你可以参考下面的代码,效果不错(把代码里的路径改成你自己的):

    from selenium import webdriver
    from selenium.webdriver.ie.service import Service
    
    ser = Service("E:\webdriver\IEDriverServer.exe")
    ieOptions = webdriver.IeOptions()
    ieOptions.add_additional_option("ie.edgechromium", True)
    ieOptions.add_additional_option("ie.edgepath",'C:Program Files (x86)MicrosoftEdgeApplicationmsedge.exe')
    driver = webdriver.Ie(service = ser, options=ieOptions)
    
    driver.get('https://www.google.com/')
    print("ANYTHINGGG")
    

【讨论】:

  • 还是不行,和你的一模一样,我用的IEDriver版本是4.6.0.0(今天最后一个),你可能认为是驱动问题?如果是这样,你有一个旧版本的链接吗? (我只是在互联网上找不到旧版本)
  • “驱动程序可执行文件需要放在 PATH 中”意味着我需要将驱动程序的位置放在我的“环境变量”中?
  • 我使用 Python 3.9.5。我用 32 位的 Windows IE Driver 4.6.0.0 测试,它仍然有效,所以我认为驱动程序版本是可以的。对于你的第二个问题,是的,你需要将 IE 驱动程序位置放在环境变量 -> 路径.此外,请不要忘记认识所有Required Configuration.您使用哪个版本的 Selenium?我用硒 4.3.0.
  • 它现在工作了,我需要设置在 Required Configuration 上显示的注册表项
【解决方案2】:

它现在可以工作,在满足所需的配置之后,特别是在 windows 上创建注册表条目之后,谢谢 Yu Zhou

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-03
    • 2011-11-05
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多