如何使用selenium单击表单中的类

时间:2017-04-02 16:21:44

标签: angularjs forms selenium xpath selenium-webdriver

我正在尝试编写一个点击电子邮件和密码字段的测试用例。棘手的部分是这些字段在一个表单中,所以我尝试使用xpath,cssSelector,甚至partialLinkText和Selenium仍然找不到该元素。

这是页面的代码:

<form class="well form-inline ng-pristine ng-scope ng-invalid ng-invalid-required" ng-submit="login()" ng-hide="loggedInUser">
         <input class="ng-pristine ng-untouched ng-invalid ng-invalid-required" ng-model="user.email" val="Your email" placeholder="Email" required="" type="text"/>
         <input class="ng-pristine ng-untouched ng-valid" ng-model="user.password" val="password" placeholder="Password" type="password"/>
         <button class="btn btn-default" type="submit">Log in</button>
</form>

我试过了:

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

driver.findElement(By.xpath("//input[@ng-model = 'user.password']"));

driver.findElement(By.cssSelector("ng-pristine ng-untouched ng-invalid ng-invalid-required"));

他们都没有工作。

0 个答案:

没有答案