Selenium定位输入(Angular.JS)

时间:2017-11-29 20:23:30

标签: angularjs selenium

我刚开始使用Selenium来自动化e2e测试。我怎么能找到以下输入?

<input type="text" class="input-xlarge ng-pristine ng-invalid ng-invalid-required" data-ng-model="model.campaign.name" required="" data-ng-disabled="model.isDisabled">

到目前为止尝试通过定位@ ng-repeat来获取输入,遗憾的是没有运气。而班级无法工作:)

browser.find_element_by_xpath("//*[@ng-repeat='model.campaign.name']")

1 个答案:

答案 0 :(得分:0)

尝试组合使用xpath

//input[@data-ng-model='model.campaign.name' and @class='input-xlarge ng-pristine ng-invalid ng-invalid-required']

您还可以尝试 execute_script

element=driver.find_element_by_xpath("//input[@data-ng-model='model.campaign.name' and @class='input-xlarge ng-pristine ng-invalid ng-invalid-required']") 
//operation you wanted it is just an example
driver.execute_script("arguments[0].click();", element)