I have been trying out a lot of different ways to click on a particular element on the browser using Nightwatch.js (nth-child, nth-of-type, etc), and so far I am not able to find the correct element. I am trying to click on the 2nd "More" button on the screen.
The HTML looks like this. Both of the "More" buttons have the exact same class, and are nested within a div that has a key difference in the class, in that one is called discover-teams and the second is nested within a div that has a class of discover-athletes. If I try something like this, I end up clicking on one of the follow buttons on the image
.click('.discover-athletes div:nth-child(3) button')
If anyone knows of the best way to do this I would greatly appreciate it. So far I am coming up short. Much obliged
Nightwatch. js is a Selenium wrapper that provides several out-of-the-box commands and assertions for performing various operations on the page. The commands and assertions are clean and straightforward, enabling you to develop tests very quickly using Javascript (specifically, Node. js).
Nightwatch. js framework is a Selenium-based test automation framework, written in Node. js and uses the W3C WebDriver API (formerly Selenium WebDriver). It works by communicating over a restful HTTP API with a WebDriver server (such as ChromeDriver or Selenium Server).
I see that the page has two ".discover-athletes" so the selector for 2nd button should be :
'test' : function(browser){
const 2ndSelector = 'div[class="discover-athletes"]:nth-child(2) > div:nth-child(3) > button';
browser.click(2ndSelector);
}
You need symbol ">" to make selector more accurate.
Edit:there is only 1 ".discover-athletes",but it make no difference.
'test' : function(browser){
const 2ndSelector = 'div[class="discover-athletes"] > div:nth-child(3) > button';
browser.waitForElementVisible(2ndSelector,5000,false,function(result){
browser.click(2ndSelector);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With