如何在以下示例中按模型或名称标识元素? [英] How can i identify element by model or by name in this the following example?
问题描述
我正在使用量角器来自动化我的测试,为了点击登录按钮,当我尝试按名称,xpath,id ...识别元素时,无法执行操作。
I 'm using protractor to automate my tests, in order to click into the login button the action couldn't be executed when i tried to identify element by name, xpath, id ...
element(by.name('Login')).click();
仅当我通过css识别它时才有效:
It works only when i identify it by css :
element(by.css('.login-button')).click();
或
element(by.css('button[ng-disabled=clicked]')).click();
但是测试通过的问题是用户没有重定向到主页,即使我放了浏览器。睡眠(8000);
是否使用元素正确识别登录按钮(by.css('button [ng-disabled = clicked]'))。click();
?
But the problem the test is passed and user isn't redirected to home page even if i put browser.sleep(8000);
Is the login button identified by the right way with element(by.css('button[ng-disabled=clicked]')).click();
?
你可以在这里找到html代码:
You can find here the html code :
<md-button type="submit" class="md-raised login-button" ng-disabled="clicked" translate="login.LOGIN">Login</md-button> </section>
</div> </fieldset> </form> <md-divider></md-divider> <footer class="login-footer"> <div layout="row" layout-align="center center"> <md-button ng-click="goToCustomerCare()" class="login-footer-link" translate="login.CUSTOMER_CARE">Contact Customer Care</md-button> <div> | </div> <md-button ng-click="showDisclaimer()" class="login-footer-link" translate="login.DISCLAIMER">Disclaimer</md-button> </div> </footer> </div>
推荐答案
HTML代码中有几个按钮可供您使用发布了,但是如果你想点击登录按钮,你应该能够
There are a few buttons in the HTML code that you posted, but if you are trying to click the login button, you should be able to do
$('.md-raised').click(); or $('.md-raised.login-button').click();
这应该按类搜索元素。
这篇关于如何在以下示例中按模型或名称标识元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!