<html>
<body>
<div id="login-box" class="form-box">
<form id="frmlogin" class="form" name="frmlogin" method="post">
<div class="body">
<div class="form-group">
<input id="email" class="form-control" type="text" maxlength="50" value="dfsf@gmail.com" placeholder="Email" name="email">
<span class="red">Please provide a valid email address</span>
</div>
<div class="form-group">
<input class="form-control" type="password" maxlength="15" placeholder="Password" name="password">
<span class="red">Password must not be empty</span>
</div>
</div>
</form>
</div>
</body>
</html>
I need to get "Please enter a valid email address" and "Password must not be empty" using nth-child
c cssSelector
.
I tried the following snippet:
// Case 2
driver.findElement(By.name("email")).clear();
driver.findElement(By.name("email")).sendKeys("");
String a=driver.findElement(By.cssSelector("form#frmlogin div.form-group:nth-child(1)>span")).getText();
System.out.println(a);
if(a.contains("valid email address"))
{
System.out.println("Login test case2 Passed");
}
else
{
System.out.println("Login test case2 Failed");
}
The result is NoSuchElementFound
.
Sugan
source
to share