waitForElementVisible xPath Multiple Elements get visible element and click it

307 views
Skip to first unread message

Craig Allardyce

unread,
Nov 3, 2015, 11:17:42 AM11/3/15
to NightwatchJs
After loading a webpage, I need to click a 'next' button. I use the xpath to wait for it to become visible, then click it:

.waitForElementVisible('//*[@class="client-action-button"][.="next"]', config.timeout)
.click('//*[@class="client-action-button"][.="next"]');

This gives an output 'Warn: WaitForElement found 3 elements for selector "//*[@class="client-action-button"][.="next"]". Only the first one will be checked.'

However the first element is never visible, the second or third element is. Is there any way to wait for the visible element and then click it?

I could try selecting the nth element, eg using the xPath: 
(//*[@class="client-action-button"][.="next"])[2]
However I would like to avoid this.

Thanks, Craig.

Derrick Schmidt

unread,
Nov 10, 2015, 12:20:12 PM11/10/15
to NightwatchJs
If you want to wait for the first button only, you should try making our selector a bit more specific. You might want to try adding an parent element or class that only the first button will have.
Reply all
Reply to author
Forward
0 new messages