Get element by cssSelector in Selenium (Java) -


<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 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 empty</span>                     </div>                 </div>             </form>         </div>     </body> </html> 

i need "please provide valid email address" , "password must not empty" using nth-child in cssselector.

i tried below 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");     } 

it results in nosuchelementfound.

you can use element selector

by.cssselector("input[name=email]") 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -