OnetapInc / chromy

Chromy is a library for operating headless chrome. 🍺🍺🍺
MIT License
605 stars 41 forks source link

How to click single element from selector #91

Closed ackmanx closed 6 years ago

ackmanx commented 6 years ago

I have a list of containers that all have a link in them. I need to click a specific one, such as the first one found, but when I use chromy.click it clicks all of them at the same time. We are using chromy 0.5.5.

chromy.click(".dossier-change-status-link[data-track='Cancel']")

Is there a way to do this without resorting to an evaluate block, such as:

chromy.evaluate(() => {
    document.querySelector(".dossier-change-status-link[data-track='Cancel']").click()
})
ackmanx commented 6 years ago

Although very fragile, I at least am able to make a highly-specific selector:

chromy.click(".appointment:nth-child(3) .appointment-task__list-entry:first-child .dossier-change-status-link[data-track='Reschedule']")
dotneet commented 6 years ago

@ackmanx There is currently not a way. If you want a option for picking single element, please implement it into .click and send PR.

ackmanx commented 6 years ago

Thanks for the info!