开发者

Does selenium not support CSS3 Selectors?

开发者 https://www.devze.com 2023-03-01 01:11 出处:网络
Not that I am master o开发者_运维知识库f CSS Selector but got to know that following is the CSS 3 selector -

Not that I am master o开发者_运维知识库f CSS Selector but got to know that following is the CSS 3 selector -

css=li:nth-child(1) div[class=team-name]

While following is CSS 2 selector -

css=li:first-child div[class=team-name]

When I use the CSS 2 selector for -

Selenium.getText("cssSelector")

I get the correct text but using CSS 3 selector throws exception stating -

Element css=li:nth-child(1) div[class=team-name] a not found

If it were only this I would probably use CSS 2 selector. But I need to iterate through couple of links and read text, i.e -

for(int i=1; i<loopCount; i++) {
        ArrayList.add(selenium.getText("css=li:nth-child("+i+") div[class=team-name] a"));
}

Now how would this be possible if I were to use CSS 2 selector.


When using nth-child for CSS3 selector in selenium, somehow selenium truncates the sting after it so it is only referring to Element css=li:nth-child(1). As a workaround use,

Element css=li:nth-child(1) > div[class=team-name]

'>' makes all the difference.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号