Java ng模型-选中复选框Xpath在chrome和IE驱动程序中不工作
Html代码:Java ng模型-选中复选框Xpath在chrome和IE驱动程序中不工作,java,angularjs,selenium,selenium-chromedriver,Java,Angularjs,Selenium,Selenium Chromedriver,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="
<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>
请澄清
但是在执行期间
Firefox-其工作正常,但未检查Chrome和IE
Firefox驱动程序:2.51.0
Chrome驱动程序:2.53.1
IE驱动程序:2.42.2给定元素无效,也无法在控制台中找到。
checkBoxSelection.click();
请根据复选框下的更改元素(逐个使用并保留,以提供给您且对您有效的为准):
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.findelelement(By.cssSelector(“input[class='ng-pristine ng untouched ng valid'])代码>
checkBoxSelection.click();
如评论中所述,我还想添加一个场景。在相同的xpath级别上可能有web元素列表。请使用索引
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:(//表[@id='tblusref']//输入[@class='ng-pristine ng untouched ng valid'])[1]
如果有任何查询,请告诉我。给定的元素无效,也无法在控制台中找到。
checkBoxSelection.click();
请根据复选框下的更改元素(逐个使用并保留,以提供给您且对您有效的为准):
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.findelelement(By.cssSelector(“input[class='ng-pristine ng untouched ng valid'])代码>
checkBoxSelection.click();
如评论中所述,我还想添加一个场景。在相同的xpath级别上可能有web元素列表。请使用索引
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:(//表[@id='tblusref']//输入[@class='ng-pristine ng untouched ng valid'])[1]
如果有任何疑问,请告诉我。您有例外吗?@Guy:我没有得到任何例外您有例外吗?@Guy:我没有得到任何例外,但是在表中有n个复选框,所以我想逐行遍历每一行并检查特定的行。请让我知道您是否想选择此选项?有秩序吗?答案已更新。请选中遍历整个表并仅选中特定复选框,w.r.t.表行:(By.xpath(“//*[@id='tblusref']]/tbody/tr[1]/td[2]..您可以尝试使用此xpath//table[@id='tblusref'](//input[@class='ng-pristine ng untouched ng ng valid'])[1]请让我知道它是否工作,以便我也可以更新答案谢谢,但在表中有n个复选框,因此我希望逐行遍历每个行并选中特定行。请让我知道您是否希望选择此选项?按顺序?答案已更新请选中遍历整个表并仅选中特定复选框,w.r.t.表格行:(By.xpath(“//*[@id='tblusref']/tbody/tr[1]/td[2]..您可以尝试此xpath//table[@id='tblusref'](//input[@class='ng-pristine ng untouched ng valid'])[1]请告诉我它是否工作,以便我也可以更新答案