0

URL- https://www.vtiger.com/begin-free-trial

Enter an invalid email address such as "abcde" and now click on Next Button. You will notice an error message which will appear for 4/5 seconds ( image below )

How can we verify this error message, I am not able to get xpath of this also.

enter image description here

2

2 Answers 2

0

The error message which you are referring is a validation message which is the outcome of Constraint API's element.setCustomValidity() method.

Note: HTML5 Constraint validation doesn't remove the need for validation on the server side. Even though far fewer invalid form requests are to be expected, invalid ones can still be sent by non-compliant browsers (for instance, browsers without HTML5 and without JavaScript) or by bad guys trying to trick your web application. Therefore, like with HTML4, you need to also validate input constraints on the server side, in a way that is consistent with what is done on the client side.


Solution

To retrieve the error message Please fill out this field. you need to:

  • Induce WebDriverWait for the desired element to be clickable.

  • Now, to extract the validationMessage and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    • Code Block:

      driver.get("https://www.vtiger.com/begin-free-trial/")
      work_email = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='email']")))
      work_email.send_keys("dggf")
      print(work_email.get_attribute("validationMessage"))
      
    • Console Output:

      Please include an '@' in the email address. 'dggf' is missing an '@'.
      
  • Using XPATH:

    • Code Block:

      driver.get("https://www.vtiger.com/begin-free-trial/")
      work_email = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='email']")))
      work_email.send_keys("dggf")
      print(work_email.get_attribute("validationMessage"))
      
    • Console Output:

      Please include an '@' in the email address. 'dggf' is missing an '@'.
      

Reference

You can find a detailed relevant discussion in:

Sign up to request clarification or add additional context in comments.

Comments

0

Try Below Code -

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
action = ActionChains(driver)

driver.get('https://www.vtiger.com/begin-free-trial/')

driver.find_element_by_name('email').send_keys("xyz")
driver.find_element_by_xpath('//button[contains(text(),"Next")]').click()

messagetoVerify = "Please include an '@' in the email address. 'xyz' is missing an '@'."
myValidationmsg = driver.find_element(By.NAME, 'email').get_attribute("validationMessage")

if myValidationmsg == messagetoVerify:
    print("Verified Validation Message")

Output -

Please include an '@' in the email address. 'xyz' is missing an '@'.

1 Comment

driver.get("vtiger.com/begin-free-trial/"); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); WebElement e1 = driver.findElement(By.xpath("//input[@name='email']")); driver.findElement(By.xpath("//button[@type='submit']")).click(); e1.sendKeys("xyz"); JavascriptExecutor js = (JavascriptExecutor)driver; String actual = (String)js.executeScript("return arguments[0].validationMessage;", e1); String expected = "Please include an '@' in the email address. 'xyz' is missing an '@'."; System.out.println(actual.equals(expected));

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.