Home > Net >  How do I get a popup validation message from a page using selenium Python?
How do I get a popup validation message from a page using selenium Python?

Time:05-24

How do I get the popup validation message "Please tick this box if you want to continue" using Selenium Python in the photo?

<input oninvalid="this.setCustomValidity('Please tick this box if you want to proceed')" oninput="this.setCustomValidity('')"  type="checkbox" id="registerTermsCheckboxId" required="">
enter image description here

Screenshot

CodePudding user response:

Try the below, I hope this will solve your issue.

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait


toolTip = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'registerTermsCheckboxId')))
hov = ActionChains(driver).move_to_element(toolTip)
txt = hov.perform()
tooltipText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'registerTermsCheckboxId'))).text
print(tooltipText)

CodePudding user response:

I got the text in the message with the following Javascriptexecutor code.

message_element = driver.find_element(By.XPATH, Locators.acceptCheckButton_xpath) accept_button_message = driver.execute_script("return arguments[0].validationMessage", message_element) print("Mesage : ", accept_button_message)

  • Related