I am currently using Nightmare.js to automate the scraping of a webpage. As a sysadmin, my understanding of Node.js and CSS is limited.
So far, I have been able to successfully use Nightmare to input and click on certain buttons in order to log in. I identified the selector by utilizing Chrome dev tools' Inspect feature. However, I noticed that what Nightmare requires for selection is not directly copy-paste-able. For example, when working with the login username box, this is the code that worked in Nightmare:
.insert('input#username.form-control', 'username')
In Chrome Dev Tools under Elements, this code appears as the first line in "Properties", but if I attempt to "Copy selector", I receive:
#username
Xpath Copy:
//*[@id="username"]
Element Copy:
<input class="form-control" type="text" cols="60" placeholder="Email (or username)" required="" name="username" id="username" value="" autocorrect="off" autocapitalize="off" autocomplete="off" background-repeat: no-repeat; background-attachment: scroll; background-size: 16px 18px; background-position: 98% 50%; cursor: auto;">
How can I translate these different formats into something usable by Nightmare.js? I feel a bit lost.
Although I managed to make it work by manually copying the property from "Properties", I wonder why I cannot directly copy it from Chrome Dev Tools. It seems like Chrome and Nightmare interpret selectors differently, and I am unsure how to bridge that gap. When looking up CSS Selector and Node.js information, I often come across suggestions to incorporate additional tools like Cheerio.js, rather than addressing the specific issue at hand.
An illustrative problem I am facing involves a button that I cannot click.
Element Copy:
<button tabindex="0" role="button" aria-disabled="false" class="dpl-button___jGBcY button-tertiary-colors button-font-size button-font-weight button-line-height button-text-transform font-family-primary button-pad button-shadow border-radius-button">Policy Tester</button>
I have experimented with various approaches based on research from here and Google, but I seem to be stuck. It is evident that I am overlooking something crucial.
Attempting .click('button#Policy Tester')
fails, possibly due to the space within the identifier.
Trying .click('button[tabindex="0"]')
results in "unable to find element by selector".
Similarly,
.click('button.dpl-button___jGBcY.button-tertiary-colors.button-font-size.button-font-weight.button-line-height.button-text-transform.font-family-primary.button-pad.button-shadow.border-radius-button')
also does not locate the element.