简体   繁体   中英

xpath with index not working as a selector

The page has 3 buttons with a certain text {text}. I want to be able to click on the first such button.

I tested an xpath on chrome console with the index and that gives out the correct button.

$x("//button[contains(text(), 'sometext')]")[0]

But when I use the exact same xpath as a selector in my nightwatch code, it doesn't seem to find it.

Whereas

selector: '//button[contains(text(), "sometext")]'

does seem to find 3 buttons but when I add [0] (as above) it fails to find the element.

I would try [1] instead of [0]. Xpath is 1 based.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM