量角器:无法点击按钮 [英] protractor : unable to click the button

查看:46
本文介绍了量角器:无法点击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是量角器 e2e 测试的新手.使用量角器编写 jasmine 测试用例.我在一个 html 文件中有两个按钮.我想选择特定按钮(begin.html 文件中的按钮)

这些没有用

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

by.linkUiSref('about-you');

在按钮上执行一些事件应该导航到下一页(关于-你)

请帮帮我

Text.html

<a ui-sref="开始"><button class="green">Text</button></a>

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

begin.html

<button class="green" id="gotest" ui-sref="about-you">开始</button>

解决方案

Protractor 工作快速且异步.因此,您的按钮单击可能只是在页面准备就绪之前执行,因此您会收到错误消息.要解决此问题,您可以先尝试使用量角器中的等待函数查找元素,然后使用等待返回的承诺,您可以单击按钮.

以下代码可能对您有所帮助-

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

希望这能解决您的问题.

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> 

解决方案

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.

这篇关于量角器:无法点击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆