繁体   English   中英

python selenium 3 Edge web 驱动程序错误

[英]Error in python selenium 3 Edge web driver

我是 selenium 的完整初学者,我编写了第一个程序只是为了连接到 Google。

from selenium import webdriver
path = "C:\\Users\\Home\\Documents\\Python37-32\\Scripts\\Code\\msedgedriver.exe"

driver = webdriver.Edge(path)

driver.get("https://google.com")

print(driver.title)"

我的 web 驱动程序版本是88.0.705.50 (Official build) (64-bit)

我使用 selenium 3 并且在运行代码时遇到此错误。 它还在打开"data:,"几秒钟,然后打开谷歌。 最后,浏览器不会保持打开状态。

  • 在导入语句的单独行上声明路径

  • 在路径中使用原始字符串或双重转义

代码:

from selenium import webdriver
path = r"C:\Users\Home\Documents\Python37-32\Scripts\Code\msedgedriver.exe"

driver = webdriver.Edge(path)
driver.get("https://google.com")
print(driver.title)

你得到什么错误? 这是浏览器使用data:,打开的默认行为,然后它将定向到您想要的网站。 浏览器没有保持打开状态可能是因为错误破坏了它。

您可以参考以下步骤在 python selenium 中自动化 Edge:

  • 确保 WebDriver 版本与 Edge 版本相同。

  • 使用以下命令安装 MS Edge Selenium 工具:

     pip install msedge-selenium-tools selenium==3.141
  • 示例代码:

     from msedge.selenium_tools import Edge, EdgeOptions options = EdgeOptions() options.use_chromium = True driver = Edge(executable_path = r"C:\Users\Home\Documents\Python37-32\Scripts\Code\msedgedriver.exe", options = options) driver.get("https://google.com") print(driver.title)

暂无
暂无

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

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