51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 4495|回复: 5

selenium rc css碰到一个问题

[复制链接]

该用户从未签到

发表于 2010-6-28 20:58:28 | 显示全部楼层 |阅读模式


实验地址
我想通过 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 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

x
回复

使用道具 举报

该用户从未签到

发表于 2010-6-29 10:53:01 | 显示全部楼层
Can you give the url you are testing?
回复 支持 反对

使用道具 举报

该用户从未签到

 楼主| 发表于 2010-6-29 12:00:44 | 显示全部楼层
我有提供的,上面的 实验地址

谢谢!

[ 本帖最后由 小米啊 于 2010-7-13 19:32 编辑 ]
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-7-13 09:41:49 | 显示全部楼层
直接用css=input[value='b'],不行吗
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-7-14 09:18:32 | 显示全部楼层
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:17 | 显示全部楼层

回复 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).
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-4-16 18:54 , Processed in 0.077502 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表