Closed eladmoshe closed 8 years ago
I found a workaround in the mailing list if anyone has this issue.
browser.element('css selector', 'select', function(result){
if (result.value && result.value.ELEMENT) {
// Element is present, do the appropriate tests
} else {
// Element is not present.
}
});
FWIW, being based off of elementiddisplayed
means it does have a dependency on the element existing on list. This is, I'm guessing, why you're getting an error. If a select
element was present on the DOM and not visible, then you should get a false return value.
I'm not sure if isVisible
is also meant (by design) to account for element present. Perhaps there's a missing isPresent
command needed to determine if an element exists in the first place - not unlike the distinctions between waitForElementVisible
and waitForElementPresent
.
Edit: Should isVisible
be changed to consider lack of presence as not-visible, then for consistency, waitForElementNotVisible
should also be updated to pass on element not found. Currently it does not, failing on element expected to be present.
I understand what you mean, makes sense. Indeed an isPresent
command is what I was looking for. I believe that it is probably a common scenario and the browser.element
option isn't documented, or at least I haven't found it.
@eladmoshe the element
method is documented under the Selenium Protocol:
http://nightwatchjs.org/api#element
These are commands that are directly tied to the selenium api and not in Nightwatch wrappers like isVisible
is.
@senocular Thanks!
Consider the following code:
If the element is visible everything works great. However, if the element is not visible the test fails with an error:
ERROR: Unable to locate element: ".my-class" using: css selector
I believe that isVisible should just return the result and never fail the test.[Nightwatch version 0.9.5; reproduced w/ Appium over iOS and Selenium over Chrome.]