硒不支持CSS3选择器? [英] Does selenium not support CSS3 Selectors?

查看:173
本文介绍了硒不支持CSS3选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不是我是CSS选择器的主人,但得知以下是CSS 3选择器 -

Not that I am master of CSS Selector but got to know that following is the CSS 3 selector -

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

-

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

当我使用CSS 2选择器时 -

When I use the CSS 2 selector for -

Selenium.getText("cssSelector")



我获得正确的文本,但使用CSS 3选择器throws异常说明 -

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

如果只是这样,我可能会使用CSS 2选择器。但我需要通过几个链接和读取文本,即 -

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

现在如果我使用CSS 2选择器, / p>

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

推荐答案

当在selenium中使用nth-child选择CSS3选择器时,selenium会截断sting,所以它只引用 Element css = li:nth-​​child(1)。作为解决方法,请使用

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]

'>'所有区别。

希望这有帮助。

这篇关于硒不支持CSS3选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆