Nightwatch - unable to locate the element

26 views Asked by At

I tried with the following XPath:
browser.click("//button[normalize-space()='Reserve a room']")

and receiving the following error message: NoSuchElementError An element could not be located on the page using the given search parameters.

screenshot

I tried with the following XPath:
browser.click("//button[normalize-space()='Reserve a room']")

2

There are 2 answers

0
Tanner Logan On

You might be able to just use this css selector:

[data-stid="navbar-quick-reserve-button"]

Additionally, you can get element selectors easily by right clicking the element in the element console -> hover over Copy -> then select 'Copy Xpath' or 'Copy Selector' for the css selector.

A good way to quickly test if element selectors are valid on the page is doing a Ctrl + F keyboard command from the element tree, then placing it in the element selector you're trying to use. If it's valid, it will be found on the page.

0
Zahidul Islam On

Try this.

browser.click('div[data-stid="navbar-quick-reserve-button"] button')

This should work also.

browser.click('button[data-stid="sticky-button"]')