ng模型-选中Xpath复选框在Chrome和IE驱动程序中不起作用 [英] ng model - check the checkbox Xpath not working in chrome and IE driver

查看:47
本文介绍了ng模型-选中Xpath复选框在Chrome和IE驱动程序中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML代码:

<table id="tblusref" style="width: auto;" onmouseover="UsortBinders()" role="grid">
<thead>
<tbody aria-live="polite" aria-relevant="all">
<tr class="ng-scope AssociateHighlight odd" >
<td class="ng-binding" style="width: 10px">1</td>
<td class=" text-center" style="width: 2px">
<input class="ng-pristine ng-untouched ng-valid" type="checkbox" ng-change="CheckChange(Ref.RecordNo,Ref.Freeze,Ref.isSelected,'US')" ng-model="Ref.isSelected">
</td>
</tr>
</tbody>
</table>

表中的每一行都有一个复选框,我想选中具有特定行的复选框,下面是我的xpath

inside the table each and every row have an checkbox and i want to check the checkbox with particular row,and below is my xpath

WebElement checkBoxSelection = driver.findElement(By.xpath("//*[@id='tblusref']/tbody/tr[1]/td[2]/input"));
        checkBoxSelection.click();

请澄清

但在执行过程中

Firefox-其正常运行,但未检查Chrome和IE

Firefox - its working correctly but Chrome and IE not checked

Firefox驱动程序:2.51.0

Firefox driver: 2.51.0

Chrome驱动程序:2.53.1

Chrome driver: 2.53.1

IE驱动程序:2.42.2

IE driver: 2.42.2

推荐答案

给出的元素无效,也无法在控制台中找到.

根据复选框的下方更改元素(使用一个,并保留为您提供使用的有效):

Please change element as per under of checkbox (Use one by one and keep whichever is proffered and working for you):

  1. WebElement checkBoxSelection = driver.findElement(By.xpath("//input [@ class ='ng-pristine ng-untouched ng-valid']")));

WebElement checkBoxSelection = driver.findElement(By.xpath("//input [contains(@ class,'ng-valid')]"))); 在这里,当您获得唯一元素时,请更改内部类的文本.

WebElement checkBoxSelection = driver.findElement(By.xpath("//input[contains(@class,'ng-valid')]")); Here change internal class text as you get unique element.

WebElement checkBoxSelection = driver.findElement(By.cssSelector("input [class ='ng-pristine ng-untouched ng-valid']")));

然后单击它.

checkBoxSelection.click();

正如评论中的讨论,我还要添加另一种方案.在xpath的相同级别可能会有Web元素列表.请使用索引.

As discuss in comment , There is one more scenario I want to add. There may be list of web elements at same level of xpath. Please use index for it.

driver.findElement(By.xpath("(//input[@class='ng-pristine ng-untouched ng-valid'])[1]"));

driver.findElement(By.xpath("(//input[@class='ng-pristine ng-untouched ng-valid'])[2]"));

依此类推...

特定于此表的解决方案是:

xpath:(//table [@ id ='tblusref']//input [@ class ='ng-pristine ng-untouched ng-valid'])[1]

如果有任何疑问,请告知我.

Please let me know If any query.

这篇关于ng模型-选中Xpath复选框在Chrome和IE驱动程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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