Unable to select the check box using leftOf

a 夏天 提交于 2021-02-10 20:47:51

问题


I am trying to click a check box which is left to the text(as-server).

My HTML code looks like this.

<td>
     <input type="checkbox" ng-model="asset.isChecked" ng-change="selectEntity(filteredTableElements,asset.id)" class="ng-valid ng-dirty ng-valid-parse ng-empty ng-touched">
</td>                                       
<td class="ng-binding">as-server</td>

The Ui for the above snippet

I went through the Karate doc and tried multiple scenarios but none of them were able to find the checkbox.

Scenario1:

* leftOf('{}as-server').find('input[type="checkbox"]').click()

output: evaluation (js) failed: leftOf('{}as-server').find('input[type="checkbox"]').click(), java.lang.RuntimeException: unable to find: {}as-server, LEFT, input[type="checkbox"] stack trace: com.intuit.karate.driver.ElementFinder.find(ElementFinder.java:120)

Scenario2:

* leftOf('{}as-server').click()

Output: evaluation (js) failed: leftOf('{}as-server').click(), java.lang.RuntimeException: unable to find: {}as-server, LEFT, INPUT stack trace: com.intuit.karate.driver.ElementFinder.find(ElementFinder.java:120)

Did I miss something here? Is there any other way of doing it in Karate?

Thanks!!


回答1:


UI testing is not easy. There can be many reasons, for e.g. Angular that you are using may be doing some extra things on the page and hiding element areas. The "friendly locators" are there as a convenience, but if they don't work out of the box, you should spend some time troubleshooting. It would be great if you follow this process so that we can improve the framework: https://github.com/intuit/karate/tree/develop/examples/ui-test

So maybe you should just try another approach and Karate gives you plenty. For example:

* locate('{}as-server').previousSibling.firstChild.click()


来源:https://stackoverflow.com/questions/63988429/unable-to-select-the-check-box-using-leftof

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!