0

This is the code which I am running in Google colab:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.edge.service import Service


# Prompt the user for Microsoft Edge browser sign-in credentials
username = input("Enter your username: ")
password = input("Enter your password: ")

# Set the path to the Microsoft Edge WebDriver executable
webdriver_path = "/usr/local/bin/microsoft-edgedriver.exe"  # Replace with the actual path

# Create a new instance of the Service object
# service = webdriver.Service(webdriver_path)

# Start the service
# service.start()

edge_options = webdriver.EdgeOptions()

# Create a new instance of the Microsoft Edge driver

driver = webdriver.Edge(executable_path=webdriver_path, options=edge_options)

# Maximize the browser window (optional)
driver.maximize_window()

# Navigate to the Microsoft sign-in page
driver.get("https://login.live.com/")

# Wait until the username field is visible
username_field = WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.NAME, "loginfmt"))
)
# Enter the username
username_field.send_keys(username)
username_field.send_keys(Keys.RETURN)

# Wait until the password field is visible
password_field = WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.NAME, "passwd"))
)

# Enter the password
password_field.send_keys(password)
password_field.send_keys(Keys.RETURN)

# Wait until the search box is visible
search_box = WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.NAME, "q"))
)
# Enter the search query
search_box.send_keys("hello")
search_box.send_keys(Keys.RETURN)

# Close the browser
driver.quit()

This is the full error block which I received

WebDriverException                        Traceback (most recent call last)
<ipython-input-24-4739c578a60b> in <cell line: 30>()
     28 # driver = webdriver.Edge(service=service)
     29 # driver = webdriver.Edge(service=Service(EdgeDriverManager().install()))
---> 30 driver = webdriver.Edge(executable_path=webdriver_path, options=edge_options)
     31 
     32 # Maximize the browser window (optional)

5 frames
/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/errorhandler.py in check_response(self, response)
    243                 alert_text = value["alert"].get("text")
    244             raise exception_class(message, screen, stacktrace, alert_text)  # type: ignore[call-arg]  # mypy is not smart enough here
--> 245         raise exception_class(message, screen, stacktrace)

WebDriverException: Message: unknown error: Microsoft Edge failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from msedge location /usr/bin/microsoft-edge is no longer running, so msedgedriver is assuming that msedge has crashed.)
Stacktrace:
#0 0x5586b70e7f93 <unknown>
#1 0x5586b6df48c1 <unknown>
#2 0x5586b6e20cdf <unknown>
#3 0x5586b6e1c1ed <unknown>
#4 0x5586b6e5cea5 <unknown>
#5 0x5586b6e54043 <unknown>
#6 0x5586b6e27941 <unknown>
#7 0x5586b6e28b5e <unknown>
#8 0x5586b70b4536 <unknown>
#9 0x5586b70b8049 <unknown>
#10 0x5586b70b7b39 <unknown>
#11 0x5586b70b8505 <unknown>
#12 0x5586b70bf9db <unknown>
#13 0x5586b70b88ae <unknown>
#14 0x5586b709218c <unknown>
#15 0x5586b70d3d08 <unknown>
#16 0x5586b70d3e44 <unknown>
#17 0x5586b70e1766 <unknown>
#18 0x7fefa654d609 start_thread

I have used same version of edgedriver and microsoft edge ,and the path is also correct and the selenium version is also latest But I still getting Error . I have also used chmod +x msedgedriver for permission for execution

ALEX
  • 1
  • I can reproduce the issue. I encountered this issue before, but the [former solution](https://stackoverflow.com/questions/66682566/ms-edge-driver-error-devtoolsactiveport-file-doesnt-exist-works-only-with) seems can't fix the issue in Google Colab. I suggest you can raise an issue on [Google Colab GitHub](https://github.com/googlecolab/colabtools/issues). Besides, I suggest that you can run Edge automation code on a local machine, it won't have such issue. – Yu Zhou Jun 12 '23 at 09:08
  • No one is replying on my issue in Google Colab Github, Can you provide me any other solution. – ALEX Jun 16 '23 at 13:11
  • I'm not familiar with Google Colab. If you want to use python to automate Edge, I suggest you can do it on your local machine. It doesn't have such issue when I run it locally using python. – Yu Zhou Jun 19 '23 at 06:56

1 Answers1

0

It'll be easier if you let a Python Selenium framework, such as SeleniumBase, handle the heavy work of configuring Edge properly for you.

pip install seleniumbase, and then run this script:

from seleniumbase import Driver

driver = Driver(browser="edge", headless=False)
driver.get("https://login.live.com/")
# ...
driver.quit()

There's also a context manager format that closes the driver automatically for you at the end of the with block:

from seleniumbase import DriverContext

with DriverContext(browser="edge", headless=False) as driver:
    driver.get("https://login.live.com/")
    # ...

SeleniumBase also has its own API with simplified methods that automatically wait for page elements to be loaded before interacting with them:

from seleniumbase import SB

with SB(browser="edge", headless=False) as sb:
    sb.open("https://login.live.com/")
    sb.type('input[name="loginfmt"]', "test@test.test")
    sb.click('input[value="Next"]')
    sb.type('input[name="passwd"]', "test")
    sb.sleep(3)

For all SeleniumBase Syntax Formats, see: https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/syntax_formats.md

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48