简体   繁体   中英

Error in python selenium 3 Edge web driver

I am a complete beginner to selenium and I wrote my first program just to connect to 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)"

My web driver version is 88.0.705.50 (Official build) (64-bit)

I use selenium 3 and I am getting this error while running the code. Also it is opening "data:," for a few seconds then opening Google. Lastly the browser doesn't stay open.

  • Declare path on a separate line from the import statement

  • Use raw string in path or double escapes

Code:

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)

What error do you get? It's the default behavior that the browser opens with data:, , then it will direct to the website you want. The browser doesn't stay opened may because the error breaks it.

You can refer to the following steps to automate Edge in python selenium:

  • Make sure the WebDriver version is the same as the Edge version.

  • Install the MS Edge Selenium tools using command below:

     pip install msedge-selenium-tools selenium==3.141
  • Sample code:

     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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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