Home > Software design >  edge browser closing automatically
edge browser closing automatically

Time:12-22

When I am trying to automate my edge browser using selenium, in code I didn't mentioned about the close keyword but my browser is running very fast and closing automatically. What could be the solution for this ?

This is my simple code

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.common.by import By

service_object = Service("C:\\Users\\piyus\\OneDrive\\Documents\\drivers\\edge\\msedgedriver.exe")

driver = webdriver.Edge(service= service_object)
driver.maximize_window()
driver.get("https://rahulshettyacademy.com/angularpractice/")
driver.find_element(By.NAME, "email").send_keys("[email protected]")
driver.find_element(By.ID, "exampleInputPassword1").send_keys("1234@Vivo")
driver.find_element(By.ID, "exampleCheck1").click()

I tried with wait keyword but that is not working for me

I want the browser should not close automatically or should not close without my instructions

CodePudding user response:

Add the below statement and try:

from selenium.webdriver.edge.options import Options

options = Options()
options.add_experimental_option("detach", True)

driver = webdriver.Edge(service= service_object, options=options)

CodePudding user response:

Are you familiar with Python breakpoints? You could drop one into your code so that your program pauses execution after reaching it.

There's a lot of info about that in this Stack Overflow post: Simpler way to put PDB breakpoints in Python code?

Eg:

import pdb; pdb.set_trace()

Once you are in a breakpoint, type c in the console and hit Enter to continue from where you left off. Or you can go line-by-line from there by using n and hitting Enter. Or to step into a method, use s and hit Enter.

If using breakpoints for debugging selenium tests that use pytest, there's also this post for reference: https://seleniumbase.com/the-ultimate-pytest-debugging-guide-2021/

  • Related