4

I'm still learning Protractor so I'm not sure if this is a simple answer that I'm not getting but I'm just trying to have the browser wait until the attribute I'm retrieving is true.

I'm testing the pizza option for this site.

Complete code:

browser.get('https://material.angularjs.org/latest/#/demo/material.components.select');

var topping = element(by.model('topping'));

topping.click();

browser.wait(function() {
    return topping.getAttribute('aria-expanded').then(function(value) {
        return value == 'true';
    });
}, 5000);

var toppingOptions = element.all(by.css('[role="option"]'));

toppingOptions.get(5).click();

expect(topping.getText()).toBe('Onion');

This gives me the error:

Element is not clickable at point (436, 693). Other element would receive the click: <md-backdrop class="md-select-backdrop md-click-catcher md-default-theme"></md-backdrop>

One more note, if I put browser.sleep(1000); after topping.click() and before browser.wait() then the test passes. So I know the rest of the test isn't what's failing. For some reason the call to wait isn't working.

I'm thinking it might have something to do with the fact that the option I'm trying to click is not technically visible when topping is clicked because it's in a ComboBox with a scroll element. If anyone knows a good way to simulate scrolling to the "onion" element it would be much appreciated as well.

Wes Thompson
  • 462
  • 1
  • 5
  • 21

3 Answers3

6

You are missing the return from the wait condition function:

browser.wait(function() {
    return topping.getAttribute('aria-expanded').then(function(value) {
        return value == 'true';
    });
}, 5000);

Note that I've also simplified the comparison logic inside the then callback.


Or, you can also wait for the option element to become visible:

var EC = protractor.ExpectedConditions;

var toppingOptions = element.all(by.repeater("topping in toppings"));
browser.wait(EC.visibilityOf(toppingOptions.first()), 5000);

toppingOptions.get(5).click();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • This doesn't seem to solve it. I still get the element is unclickable at point (x, y) error. I can see the button being clicked and then a select window starts to pop up but it seems like it's trying to click before that window fully loads. I'm testing the pizza section of [this page](https://material.angularjs.org/latest/#/demo/material.components.select) for reference. – Wes Thompson Jun 22 '15 at 03:05
  • @WesThompson got it. Can you share the complete code you have so far and the stack trace of the error you are getting? Thanks. – alecxe Jun 22 '15 at 03:08
  • @WesThompson okay, thanks for the updates. Please see one more option provided in the answer. Hope it helps. – alecxe Jun 22 '15 at 12:39
  • Just out of curiosity, what if I wanted to wait until the element was not visible? Is there an opposite of `EC.visibilityOf()`? – Wes Thompson Jun 22 '15 at 18:38
  • @WesThompson yup, `invisibilityOf` :) – alecxe Jun 22 '15 at 18:40
  • Just found it through a simple google search haha. I should do that before I make you answer a silly question. But thanks again! – Wes Thompson Jun 22 '15 at 18:44
0

I think you want something like this:

var toppingElem = by.id('#topping'); // or how ever you can designate this element

browser.wait(function() {
  return ptor.isElementPresent(toppingElem);
}, 5000);
Arthur Frankel
  • 4,695
  • 6
  • 35
  • 56
0

I came across a similar issue in one of my test where the Selenium was clicking at the wrong coordinates. Actually, Selenium was able to find the element when the element moved not very swiftly from top to center(a pop up was loaded in that fashion). Then while clicking on the element, it's position changed and click went on wrong location and hence the error. It seems to a limitation of selenium as discussed here.

If you have the same issue, better use thread.sleep with small interval.

You may also like to visit the page: Debugging "Element is not clickable at point" error

Community
  • 1
  • 1
Manu
  • 2,251
  • 19
  • 30