0

I tried:

search_recover_login_button.click()
try:
    myElem3 = driver.find_element('xpath', '//*locator').text
    return "You've got your password reset!" in myElem3
except TimeoutException:
    print ('No users found with this email')
 message = driver.find_element('xpath', '//*"]/h1').text
 assert message == "You've got your password reset!"

but it doesn't work, even when an incorrect email is used, it always looks OK.

I need to get results:
1 - when user input incorrect email, he will not see the massage "You've got your password reset!" and test will be failed, but when input correct, he go next page and see the message "You've got your password reset!" and test is pass

Jamiu S.
  • 5,257
  • 5
  • 12
  • 34

1 Answers1

0

You need to consider a couple of things:

  • find_element() on failure will return NoSuchElementException. So if you use find_element() you have to catch and handle NoSuchElementException in the except block.

  • While extracting text ideally you need to induce WebDriverWait for the visibility_of_element_located().

  • So your effective code block can be:

    search_recover_login_button.click()
    try:
        myElem3 = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//*locator"))).text
    except TimeoutException:
        print ('No users found with this email')
    message = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//*"]/h1"))).text
    assert message == "You've got your password reset!"
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • and one more thing: when i input icorrect email, it answer me that "reset password" != "You've got ..." looks like no wait for timeout, just make assert every time – Serge Shcherbinka Jan 17 '23 at 14:15
  • its because every time locator is same, just only phrase changes – Serge Shcherbinka Jan 17 '23 at 14:16
  • i've use this one try: myElem3 = WebDriverWait(driver, delay3).until(EC.visibility_of_element_located((By.XPATH, '//*[text()="You' 've got your password reset!"]'))).text except TimeoutException: print('No users found with this email') message = WebDriverWait(driver, delay3).until(EC.visibility_of_element_located((By.XPATH, '//*[text()="You' 've got your password reset!"]'))).text assert message == "You' 've got your password reset!" but now it's every time show me timeout message, but next page with this phrase appear.. – Serge Shcherbinka Jan 17 '23 at 15:37