Home > other >  how do we click a button that is not an element in the HTML code in Selenium Python?
how do we click a button that is not an element in the HTML code in Selenium Python?

Time:06-10

im trying to click the button "ok" in this image.

I want to click the button "ok" in this image this button is not an element in the HTML code so I cannot locate it by anything. this is a pop up as a result of making an error in the registration process on some website can anyone please help? and if there's a solution, can you tell me where to put it exactly in the code?

CodePudding user response:

The button has to be a element. Did you double check that maybe the entire text box has a click function that you can access?

CodePudding user response:

If I understand you correctly, you need to click ok in the alert. There are standard tools for this in selenium.

# Click the link to activate the alert
driver.find_element(By.LINK_TEXT, "See an example alert").click()

# Wait for the alert to be displayed and store it in a variable
alert = wait.until(expected_conditions.alert_is_present())

# Store the alert text in a variable
text = alert.text

# Press the OK button
alert.accept()

Check this for additional info: https://www.selenium.dev/documentation/webdriver/browser/alerts/

  • Related