繁体   English   中英

Python Selenium Inte.net Explorer 脚本不工作

[英]Python Selenium Internet Explorer scripts don't work

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

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(没问题),打开谷歌,但之后它停止了......不要打印“ANYTHINGGG”并且我无法在driver.get('https://www.google.com/')

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

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

(我用的是windows 10、python 3.7.9)

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

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

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

您还需要满足Required Configuration 有关使用 Inte.net Explorer 驱动程序在 Edge 中自动化 IE 模式的详细信息,您可以参考此文档

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

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")

在此处输入图像描述

暂无
暂无

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

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