4

I'm writing protractor tests for an existing app. I have a button called 'Decline' in a modal window, and I'm trying to click it using:

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

But I receive the below error:

UnknownError: unknown error: Element is not clickable at point (,). Other element would receive the click:

May be because I have another button called 'Decline' outside the modal window?

enter image description here

How do I click on the modal window's Decline button ?

Found that this is the js code that displays this Decline button.

.....
var content = {
          title: 'Decline',
          htmlBody: '<p>...</p> ',
          okButton: 'Decline',
          onOk: function() {
.....
4

5 回答 5

3

我的同事推荐了这个,它奏效了:

单击 First Decline 按钮打开一个模式,

睡一会,

现在单击第二个拒绝按钮。

element(by.buttonText('Decline')).click();
browser.sleep(2000);
element(by.cssContainingText('.btn', 'Decline')).click();

感谢你的帮助 :)

于 2016-06-25T10:57:27.350 回答
3

由于有两个带有按钮文本 Decline 的按钮,我们如何识别模态中的一个?

解决此问题的一种方法是改进您的定位器以在模态内容的范围内工作。但是,由于您没有提供模态的 HTML 表示,我无法为您提供具体的答案。以下是您可以改进以适合您的用例的示例:

element(by.css(".modalContent button[ng-click*=ok]")).click();
element(by.css(".modalContent")).element(by.buttonText("Decline")).click();

另一种方法是查找具有特定文本的所有按钮并过滤可见的按钮:

element.all(by.buttonText("Decline")).filter(function (button) {
    return button.isDisplayed().then(function (isDisplayed) {
        return isDisplayed;
    });
}).first().click();
于 2016-06-24T13:39:18.767 回答
0

只需按其文本搜索按钮并使用该功能click。所以对你来说它应该是这样的:

element(by.buttonText('Cancel')).click();
于 2017-08-16T14:43:29.063 回答
0

编写需要在模态窗口下显示的代码,在表单标签内。并将该表单与现有表单序列化。

于 2016-06-24T05:41:11.563 回答
-1

试试下面的代码,

var DeclineBtn = element(by.buttonText('Decline'));
browser.executeScript("arguments[0].click()",DeclineBtn.getWebElement())
于 2016-06-24T05:21:57.703 回答