[英]Watir-Webdriver, Ruby - click on the table row
I'm using Watir-Webdriver and Ruby. 我正在使用Watir-Webdriver和Ruby。 On the page I have a table of record.
在页面上,我有一张记录表。 I need to click on any row and it should go the next page.
我需要单击任何行,它应该进入下一页。 How can I click on the row?
如何单击该行? Here's the source code for each record from the table
这是表中每条记录的源代码
<tr class="ng-scope" ng-click="clickHandler({rowItem: item})" ng-repeat="item in ngModel"> <td class="ng-bindging">Sometext</td> <td class="ng-bindging">Sometext1</td> <td class="ng-bindging">Sometext2</td> <td class="ng-bindging">Sometext3</td> <td class="ng-bindging">Sometext4</td> <td> <span class="glyphicon glyphicon-play-circle"></span> </td>
Any suggestions would be appreciated. 任何建议,将不胜感激。
Thank you. 谢谢。
The key is to find unique attributes that Watir can access. 关键是找到Watir可以访问的唯一属性。 The first issue is that your angular app doesn't product valid html5 without
data-
prepended. 第一个问题是,如果没有
data-
前缀,您的角度应用程序将不会生成有效的html5。
I don't know what your other rows look like to know how to click this one versus another one, but if that attribute is unique, you could use css: 我不知道您的其他行看起来如何知道如何单击这一行与另一行,但是如果该属性是唯一的,则可以使用css:
browser.element(css: "tr[ng-repeat='item in ngModel']")
If your text is unique you could also do this (even though it is less ideal): 如果您的文字是唯一的,您也可以这样做(即使不太理想):
browser.td(text: 'Sometext').parent
As you do not care which tr
element you click, you could simply click the first tr
element in the table: 由于您不必关心单击哪个
tr
元素,因此只需单击表中的第一个tr
元素:
record_table = browser.table
record_table.tr.click
If the first row is a header row, you might need to click the last row instead: 如果第一行是标题行,则可能需要单击最后一行:
record_table = browser.table
record_table.trs.last.click
Note that browser.table
will click the first table on the page. 请注意,
browser.table
将单击页面上的第一个表。 If there are more tables on the page, you will want to be more specific - eg browser.table(id: 'some_id')
. 如果页面上还有更多表,则将需要更具体-例如
browser.table(id: 'some_id')
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.