chromeless
chromeless copied to clipboard
Click an element when there are more than one element with the same name
Is there any solution for click an element of a website when there are more than one element with the same name and properties?
Click only get as input the selector, but there is a problem if there are more than one selector with the same name.
I believe, by default, the first element is clicked if there's a list of them. We don't have a method or way to select from a NodeList what element to perform the click action on
I will create a PR with my solution.
Bump for the PR to get pushed through! I'm experiencing the same issue.
A workaround would be to use evaluate
:
.evaluate(() => {
document.querySelectorAll('.myclass')[2].click(); //3rd element
return "anything";
})
more generally it would be nice if you could either click on an actual dom element, or else pass a function in place of a selector:
.type('[email protected]', 'input#username')
.type('very secure password', 'input#password')
.click(()=> {
[].map.call(document.querySelectorAll('button'), btn => btn.textContent === 'Log In'))
})
.wait(() => {
document.body.textContent === 'if this method returns truthy the wait finishes'
})