问题是选项标签发生变化,因此我无法通过标签抓取.我需要通过说选项[0]抓住
任何的想法?
我正在使用Selenium IDE(Firefox),这是我要问的一块:
<tr>
<td>select</td>
<td>dateRangeString</td>
<td>index=1</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
最后一个TD在IDE中有VALUE字段,
我已经定位了select元素,但我需要模拟用户选择第一个选项.我看到这样做的唯一方法是在IDE的VALUE部分使用LABEL ="string",但字符串是动态的,因此不起作用!
Aut*_*ter 11
您可以使用XPath选择它//select/option[index].
请记住,XPath是标准的基于1的索引.
问题更新后编辑
您可以使用多种不同方式从选择中选择一个选项.下面已经从Selenium IDE中复制了如何创建选项定位器.要选择它的第一个项目index=0
select(selectLocator,optionLocator)参数:
Run Code Online (Sandbox Code Playgroud)* selectLocator - an element locator identifying a drop-down menu * optionLocator - an option locator (a label by default) Select an option from a drop-down using an option locator. Option locators provide different ways of specifying options of an HTML选择元素(例如,用于选择特定选项,或用于断言所选选项满足规范).选择选项定位器有多种形式.
* label=labelPattern: matches options based on their labels, i.e. the visible text. (This is the default.)
o label=regexp:^[Oo]ther
* value=valuePattern: matches options based on their values.
o value=other
* id=id: matches options based on their ids.
o id=option1
* index=index: matches an option based on its index (offset from zero).
o index=2
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)If no option locator prefix is provided, the default behaviour is to在标签上匹配.
而不是使用label ="",尝试使用index ="1"(以选择第一个元素).对于这种情况,Selenium提供label ="",id ="",value =""和index ="".有关详细信息,请参阅:
http://release.seleniumhq.org/selenium-core/0.8.0/reference.html
| 归档时间: |
|
| 查看次数: |
29089 次 |
| 最近记录: |