Selenium如何访问同一个css类的两个控件 [英] Selenium how to access two controls of same css class

查看:291
本文介绍了Selenium如何访问同一个css类的两个控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用selenium ide进行测试。
我的目标是验证以下

I am doing testing using selenium ide. My objective is to verify the following

1)文本框的最大和最小长度属性。
2)验证标签的文本

1) Max and Min length property of text boxes. 2) Verify the texts of the labels

我的html代码如下:

My html code is as below:

<div class="control-group">
                                <label class="control-label" for="input01">Email</label>
                                    <div class="controls">
                                        <input name="data[Salon][username]" class="span4" id="username" placeholder="Username or Email" type="text"/>                                   
                                    </div>
                            </div>

                            <div class="control-group">
                                <label class="control-label" for="input01">Password</label>
                                    <div class="controls">
                                        <input name="data[Salon][password]" class="span4" id="password" placeholder="Required" type="password"/>                                                                    
</div>

但在上面,我面临以下问题:

But in the above I am facing following problems:

a)我在访问assertText或assertElementPresent的标签时遇到问题,因为它们具有相同的类名。

a) I have problem in accessing the labels for assertText or assertElementPresent since they are having same class name.

b)我不知道如何验证文本框的最大和最小长度属性。

b) I don't know how verify the Max and Min length property of the Text boxes.

请注意,当我尝试使用

document.getElementsByClassName("control-label")

I am getting the following error:

[error] locator not found: document.getElementsByClassName("control-lable"), error = TypeError: e.scrollIntoView is not a function


推荐答案

您可以通过以下方式访问第一个标签:

You can access first label via:

css=div[class='control-group'] label[class='control-label']:contains('Email')

通过:

css=div[class='control-group'] label[class='control-label']:contains('Password')

使用这些命令assertElementPresent,元素定位器中的contains允许您验证文本。

Use these with command assertElementPresent, "contains" in element locator allows you to verify text in it.

也可以使用xpath:

Also you can use xpath:

//div[@class='control-group']//label[@class='control-label'][text()='Email']
//div[@class='control-group']//label[@class='control-label'][text()='Password']

通常maxlength属性设置为输入的属性,但我无法看到它在你的html代码..但你可以尝试:

Usually maxlength property is set as attribute of the input, but i can't see it in your html code.. But you can try:

storeAttribute(Selenium IDE的命令)和作为目标你可以使用xpath:

storeAttribute (Selenium IDE's command) and as target you can use xpath:

/div[@class='control-group']//label[@class='control-label'][text()='Email']/@maxlength

将其保存到一些var(例如设置为值字段smthg像attLength),然后回显此var像:Selenium IDE的命令echo和放到目标字段$ {attLength}

save it to some var (eg set to the value field smthg like attLength) and then echo this var like: Selenium IDE's command echo and as put to the target field ${attLength}

这篇关于Selenium如何访问同一个css类的两个控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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