protractor : unable to click the button

天大地大妈咪最大 提交于 2019-12-20 03:41:22

问题


Im new to protractor e2e testing. Writing jasmine test cases using protractor. I have two buttons in a html file. I want to select the specific button(button in begin.html file)

These did not work

element(by.id('gotest')).click();

by.linkUiSref('about-you');

performing some event on the button should navigate to next page(about-you)

Please help me

Text.html

<div class="button">
    <a ui-sref="begin">
        <button class="green">Text</button>
    </a>
</div>

<ng-include src="'../begin.html'" class="hidden"></ng-include>

begin.html

<div class="button">
    <button class="green" id="gotest" ui-sref="about-you">Start</button>
</div> 

回答1:


Protractor works fast and asynchronous. So, your button click might just be executed even before the page is ready and hence you get errors. To resolve this issue you can first try to find the element using wait function in protractor and then using the promise that the wait returns, you can click on the button.

Below code might help you -

var elementToClick = $('#gotest');
browser.wait(protractor.ExpectedConditions.elementToBeClickable(elementToClick), 10000)
.then ( function () {
    elementToClick.click();
});

Hope this solved your problem.




回答2:


Try:

element(by.buttonText('Start')).click();

otherwise please send what error you have got.



来源:https://stackoverflow.com/questions/27955231/protractor-unable-to-click-the-button

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