-1

I am unable to extract validation messages using get text in selenium my HTML is

<div class="ant-alert-message"\>The email address or the password is incorrect. Please re-enter.</div\>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

To print the validation message The email address or the password is incorrect. Please re-enter. you can use either of the following Locator Strategies:

  • Using css_selector and get_attribute("innerHTML"):

    print(driver.find_element_by_css_selector("div.ant-alert-message").get_attribute("innerHTML"))
    
  • Using xpath and text attribute:

    print(driver.find_element_by_xpath("//div[@class='ant-alert-message'][contains(., 'address or the password')]").text) 
    

Ideally you need to induce WebDriverWait for the presence_of_element_located() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR and text attribute:

    print(WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "div.ant-alert-message"))).text)
    
  • Using XPATH and get_attribute():

    print(WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@class='ant-alert-message'][contains(., 'address or the password')]"))).get_attribute("innerHTML"))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352