html - How select an attribute inside list using css selector and Selenium -


i'm trying use css selector element inside <li> selenium

that's have:

<div id= "popup">   <ul>      <li>         <div id="item" option= "1" ....> </div>      </li>      <li>         <div id="item" option= "2" ....> </div>      </li>   </ul>  </div> 

i need second div, option=2. tried:

webdriver.findelement(by.cssselector("#popup > ul li:nth-child(n) [option=2]"); 

that works fine in console of chrome not selenium :/ what's wrong this?

two issues:

  • :nth-child(n) means "any value of n" result in every child being matched. mean use :nth-child(2) if want make sure element under second li. or if doesn't matter li appears in, can rid of :nth-child() selector entirely.

  • the value in attribute selector must quoted if begins digit, [option='2'].

the correct selector, therefore, is:

webdriver.findelement(by.cssselector("#popup > ul li:nth-child(2) [option='2']"); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -