chromeless icon indicating copy to clipboard operation
chromeless copied to clipboard

Click an element when there are more than one element with the same name

Open kujaomega opened this issue 6 years ago • 5 comments

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.

kujaomega avatar Aug 16 '17 18:08 kujaomega

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

joelgriffith avatar Aug 16 '17 22:08 joelgriffith

I will create a PR with my solution.

kujaomega avatar Aug 17 '17 00:08 kujaomega

Bump for the PR to get pushed through! I'm experiencing the same issue.

devfordays avatar Aug 20 '17 20:08 devfordays

A workaround would be to use evaluate:

.evaluate(() => {
  document.querySelectorAll('.myclass')[2].click();  //3rd element
  return "anything";
})

forzagreen avatar Jun 05 '18 17:06 forzagreen

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'
       })



mbildner avatar Jul 06 '18 18:07 mbildner