CSS list items selection query | Selenium Forum
M
Posted on 21/11/2015
String res=cd.findElement(By.xpath("//*[starts-with(@id,'p_1383846')]/li[2]/a")).getText();

System.out.print(res);

Giving me second value from list of values ( when I typed games in yahoo search )

But
If i using CSS selector

String res=cd.findElement(By.cssSelector("ul[id^='p_13838465-'] li[2] ")).getText();

Throwing error.

Please help me in telling correct CSS selector command and why error thrown

M
Replied on 22/11/2015

You can use-
ul[id^='[b:26mdno3f]yui_3_12_0_1_1448180105579[/b:26mdno3f]']>li:nth-of-type(2)>a
ul[id^='[b:26mdno3f]yui_3_12_0_1_1448180105579[/b:26mdno3f]'] li:nth-of-type(2) a


M
Replied on 22/11/2015

I tried in chrome. Id may differ in firefox. But the concept is same.
li[2] - li:nth-of-type(2)


M
Replied on 22/11/2015

that ID won't work. it keeps on changing.


M
Replied on 22/11/2015

try to use Robot frame work in java.