51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 4793|回复: 5
打印 上一主题 下一主题

selenium rc css碰到一个问题

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 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
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2010-6-29 10:53:01 | 只看该作者
Can you give the url you are testing?
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2010-6-29 12:00:44 | 只看该作者
我有提供的,上面的 实验地址

谢谢!

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

使用道具 举报

该用户从未签到

4#
发表于 2010-7-13 09:41:49 | 只看该作者
直接用css=input[value='b'],不行吗
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 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.
回复 支持 反对

使用道具 举报

该用户从未签到

6#
 楼主| 发表于 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-11-24 07:51 , Processed in 0.071113 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

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