How to check if element exists without erroring in NW 2 #3242
Unanswered
RezhaBlue
asked this question in
Help Needed
Replies: 1 comment 1 reply
-
I havent upgrade to V2 but i do see isPresent() method. Check on it. Else for V1 i was using a custom command : module.exports.command = function (selector, callback) {
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is an age old question but I am hoping with NightwatchJS 2.0 there are better ways to address this.
I need to know if an element exists in order to test a specific logic.
If the element does not exist I just want to skip that logic and move on.
It is not an error if it does not exist and I do not want to fail or assert it as such because there is no bug.
E.g. I have a set of HTML button elements on a page.
I want to check if a specific button exists.
It is saved as '@bluebutton' with a complex and verbose xpath selector in my Page Objects.
If it does I want to be able to click it and do some further work. If the button does not exist I just want to note in the report that it does not exist so its logic is being skipped and continue the rest of the test case.
How do I do this in NW 2?
I have tried using findElements but it throws an error when the button is not there. when the button is there it works but requires parsing JSON AND iterating an array, not either or nor neither.
I have also tried:
Beta Was this translation helpful? Give feedback.
All reactions