Python Selenium Internet Explorer脚本不工作

ajsxfq5m  于 2022-11-24  发布在  Python
关注(0)|答案(1)|浏览(198)

如果我编写一个简单的脚本,如下所示:

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模式的边缘(没有问题),打开谷歌,但之后它停止...不要打印“ANYTHINGGG”,我不能编程后的任何driver.get('https://www.google.com/')
这个问题似乎出现在任何站点。
有人知道该怎么解决吗?
(我用的是windows 10,python 3. 7. 9)
只是希望代码不会在driver.get('https://www.google.com/')上停止

qnakjoqk

qnakjoqk1#

如果要使用IEDriver自动化Edge IE模式,您需要:
1.使用指向Microsoft Edge浏览器的其他属性定义InternetExplorerOptions
1.启动InternetExplorerDriver的示例并传递给它InternetExplorerOptions。IEDriver启动Microsoft Edge,然后在IE模式下加载您的Web内容。
您还需要满足必需的配置。有关使用Internet Explorer驱动程序在Edge中自动执行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)\Microsoft\Edge\Application\msedge.exe')
driver = webdriver.Ie(service = ser, options=ieOptions)

driver.get('https://www.google.com/')
print("ANYTHINGGG")

相关问题