I am trying to have selenium open a website in Microsoft Edge, and it will not open. The code I am using is
from selenium import webdriver
# create webdriver object
driver = webdriver.ChromiumEdge()
# get goodle.com
driver.get("https://google.com")
It returns this error:
File "c:\Users\Henry\OneDrive\Desktop\Genetic programming\starthere.py", line 21, in <module>
driver = webdriver.ChromiumEdge()
File "C:\Users\Henry\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\edge\webdriver.py", line 61, in __init__
super().__init__(DesiredCapabilities.EDGE['browserName'], "ms",
File "C:\Users\Henry\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__
self.service.start()
File "C:\Users\Henry\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'msedgedriver' executable needs to be in PATH. Please download from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
I did add the Webdriver exe file to the path, but it still gives this error.
CodePudding user response:
You can directly pass the absolute path to help it locate your driver.
from selenium import webdriver
driver = webdriver.Edge('C:\path\to\msedgedriver.exe')
#If the first path does not work, try the following one.
driver = webdriver.Edge('C:\\path\\to\\msedgedriver.exe')
driver.get("https://google.com")
CodePudding user response:
Instead of adding it to the PATH
try this way pointing directly to the executable:
from selenium import webdriver
from selenium.webdriver.edge.service import Service
s = Service(executable_path=r'C:\path\to\msedgedriver.exe')
driver = webdriver.Edge(service=s)