I'm very new on web developing. I want to ask on how Can I automatically Click the second href, that contains the word "login"
This is the code that I tried
document.querySelector('a[href*="/a/login.php?"]')[2].click();
I'm very new on web developing. I want to ask on how Can I automatically Click the second href, that contains the word "login"
This is the code that I tried
document.querySelector('a[href*="/a/login.php?"]')[2].click();
You need querySelectorAll for this
and since it's an array-like collection it starts with a zero index, which means you need to take [1]
instead of [2]
document.querySelectorAll('a[href*="/a/login.php?"]')[1].click();
function querySelector() returning only 1st element. You need to use .querySelectorAll() instead
const links = document.querySelectorAll('.container a');
links[1].click()
<div class="container">
<a href="#">link1</a>
<a href="#">link2</a>
</div>