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