51Testing软件测试论坛

标题: selenium rc css碰到一个问题 [打印本页]

作者: 小米啊    时间: 2010-6-28 20:58
标题: selenium rc css碰到一个问题
[attach]63349[/attach]

实验地址
我想通过 css定位到第二个input
我的代码是

selenium.type("css=div#J_MS_Form form input:nth-child(2)","b")
selenium.type("css=div#J_MS_Form form input:nth-of-type(2)","b")

用css怎么都没有取到,这个问题要怎么解决呢?
谢谢!

[ 本帖最后由 小米啊 于 2010-7-13 19:32 编辑 ]
作者: goal1860    时间: 2010-6-29 10:53
Can you give the url you are testing?
作者: 小米啊    时间: 2010-6-29 12:00
我有提供的,上面的 实验地址

谢谢!

[ 本帖最后由 小米啊 于 2010-7-13 19:32 编辑 ]
作者: 测试侠    时间: 2010-7-13 09:41
直接用css=input[value='b'],不行吗
作者: goal1860    时间: 2010-7-14 09:18
Sorry for the late response, pretty bust recently, guess you have figured out the answer
The correct expression is:
selenium.type("css=div#J_MDG_Form form input:nth-child(4)","b")
You may noticed that I made 2 changes:
- MS -> MDG, don't know the reason, taobao may changed their code.
- nth-child(2) ->  nth-child(4). The 2nd input which you look for is actually 4th children. "input:nth-child(2)" means the 2nd children which is "input", may be different against your initial assumption.

Don't use nth-of-type. This pseudo class is not supported by selenium. Find the release notes:
http://release.seleniumhq.org/se ... l/0.9.2/doc/dotnet/

Personally I am strongly against css locators sicne the big compatibility problem accross browsers. Both of these 2 pseudo classes are not support by IE. As functional testing, performace is not the No1 priority. Maintainabilty is something on top of my mind.
作者: 小米啊    时间: 2010-8-10 16:37
标题: 回复 5# 的帖子
谢谢!

css=cssSelectorSyntax: Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
css=a[href="#id3"]
css=span#firstChild + span
Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, nly-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2