0

I am trying:

while(browser.assert.elementPresent("div[school-addlimit='2']>button[disabled='disabled']")!=null){
            createSchoolPage
                .click_add_button();
        }

if I use for loop without using condition, it works fine.

What am I doing wrong here?

paul
  • 4,333
  • 16
  • 71
  • 144

1 Answers1

0

browser.assert.elementPresent returns reference to browser object so you can chain your commands like browser.assert.elementPresent(".....") .click("......") .doAnotherAssertion("....") Because of that, your loop is infinitive

If you want to check if element presents on the page, and if so, then click on it, do it in that way:

var selector = "div[school-addlimit='2']>button[disabled='disabled']"; browser.element('css selector', selector, function(response) { if (response.status !== -1) { createSchoolPage.click_add_button(); } })

or

var selector = "div[school-addlimit='2']>button[disabled='disabled']"; browser.waitForElementVisible(selector, defaultMaximumWaitTime, false, function(result) { if (result.value) { createSchoolPage.click_add_button(); } }

update

I see 3 possibilities when element is in DOM but it is not clickable:
* button is hovered by other element
* button is disabled
* button is in DOM but it is not visible

In first case, you may use https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint to check if the button is on top

In second case, you need to update your css selector to find element that is not disabled (ex. https://stackoverflow.com/a/9207343/787828) (or find any element and then check their attributes)

In third case, use browser.waitForElementVisible

Community
  • 1
  • 1
nirmus
  • 4,913
  • 9
  • 31
  • 50
  • @nimus `response.status` appears always true because element is always available in dom. How to check something like `response.clickable`? Thanks!! – paul Aug 25 '16 at 19:20