无法使用Selenium Python EdgeOption启动边缘浏览器

2024-06-02 06:56:14 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试了以下方法。 第一种方法:

from selenium import webdriver
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
options = EdgeOptions()
options.use_chromium = True
driver = Edge(options = options)
driver.get('https://www.google.com/')

输出:FileNotFoundError:[Errno 2]没有这样的文件或目录:“msedgedriver”

第二种方法:给出了edge驱动程序的路径,但它也没有启动

desired_cap = {}
sys.path.append('/Users/lr02023/Downloads/edgedriver_mac64/msedgedriver')
options = EdgeOptions()
options.use_chromium = True
driver = Edge(options 
= options,executable_path='/Users/XXXXX/Downloads/edgedriver_mac64/
msedgedriver',capabilities=desired_cap)

输出:selenium.common.exceptions.SessionNotCreatedException:消息:未创建会话:未找到匹配的功能

在第二种方法中,尝试使用options.binary_位置,但仍然存在相同的错误,未找到匹配功能

正在发挥作用的第三种方法:

from selenium import webdriver
driver = 
webdriver.Edge(executable_path='/Users/XXXXX/Downloads/edgedriver_mac64/
msedgedriver',capabilities=desired_cap)
driver.get('https://www.google.com/')

输出:打开google.com

第三种方法是使用Selenium+Python启动edge,但我想向edge浏览器添加扩展并在其上进行测试,这样就不起作用了。 已尝试的选项。添加扩展名(“CRX文件路径”)->;边缘选项不起作用

是否有人可以使用Selenium+Python向edge浏览器添加扩展?有人可以帮助我吗


Tags: 方法fromimportcomdriverseleniumgoogleoptions
1条回答
网友
1楼 · 发布于 2024-06-02 06:56:14

您曾问过,“Is there any way to add an extension to edge browser using Selenium + Python?

下面是Selenium Python示例代码,可以帮助您向边缘浏览器添加扩展

from msedge.selenium_tools import Edge, EdgeOptions
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

options = EdgeOptions()
options.use_chromium = True
#options.add_argument("-inprivate")
options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
options.add_extension(r"Path_to_your_extension_here...\extension_name.crx") # Modify the path here...
capabilities = DesiredCapabilities.EDGE

driver = Edge(executable_path = r"Path_to_the_Edge_web_driver_here..\msedgedriver.exe", options = options,desired_capabilities=capabilities) # Modify the path here...

driver.get("http://Your_website_address_here...") # Modify the URL here...

# Perform some automation here...

driver.quit

MS Edge 89.0.774.75版本的测试结果:

enter image description here

此外,您可以根据自己的需求修改代码示例

相关问题 更多 >