最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Browser.wait() until .getAttribute() returns true - Stack Overflow

programmeradmin4浏览0评论

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('ponents.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.

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/latest/#/demo/material.ponents.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.

Share Improve this question edited Jun 22, 2015 at 5:12 Wes Thompson asked Jun 22, 2015 at 2:18 Wes ThompsonWes Thompson 4731 gold badge7 silver badges21 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 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 parison logic inside the then callback.


Or, you can also wait for the option element to bee 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();

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);

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

发布评论

评论列表(0)

  1. 暂无评论