How to locate the Constraint validation text using Selenium and Java
I'm trying to make a Selenium test script that checks if a bootstrap validation popover appears when submitting a form containing a bad value.
My script below returns this error:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#amount"}
Relevant code:
WebDriver driver = new ChromeDriver()
WebElement field = driver.findElement(By.id("amount")); //errors here every execution
Boolean is_valid = (Boolean)WebUI.executeScript("return arguments[0].checkValidity();", field);
if (!is_valid) {
//intentionally fail test
}
When I inspect the form field, I see the id
equals amount
, so why am I unable to find this element in Selenium?
EDIT Here's my full script that I omitted for brevity:
WebUI.openBrowser('')
WebUI.navigateToUrl('Foo')
WebUI.setText(findTestObject('Object Repository/Page_bar/input_concat(Recipient, , s email address)_email'), 'fakepersonaluser1@example.com')
WebUI.setText(findTestObject('Object Repository/Page_bar/input_Amount (USD)_amount'), '10001')
WebUI.click(findTestObject('Object Repository/Page_bar/button_Send Payment'))
WebDriver driver = new ChromeDriver() WebElement field =
driver.findElement(By.id("amount")); Boolean is_valid =
(Boolean)WebUI.executeScript("return arguments[0].checkValidity();", field);
if (!is_valid) { //intentionally fail test }
WebUI.closeBrowser()
Comments
Post a Comment