I have a login button but it doesn't have an id.
<input class="loginBtn" name="submit" value="Log in" tabindex="2" type="submit">
because of that document.getElementById("submit").click();
can't find the button and returns
TypeError: null is not an object (evaluating 'document.getElementById("submit").click')
undefined:4
:5
How do i find the element by any of the above values that i do know? Because i do not have an ID to use.
try:
document.getElementsByClassName("loginBtn")[0].click();
or
document.getElementsByName("submit")[0].click();
document.getElementsByName("submit")[0].click();
works! Why did I need [0]?
document.getElementById
returns a single element.
document.getElementsByName
returns a collection (notice the suffixed "s"), so you need [0] to reference the first element.
Thank you for submitting this ticket!
This issue tracker primarily serves as the tool to report and track bugs, defects, and development tasks.
For general question, code review request, build problem, or other related discussion, please post it to either:
If you have not read it yet, please check also a few tips on Effective Q&A.
Most helpful comment
try:
document.getElementsByClassName("loginBtn")[0].click();
or
document.getElementsByName("submit")[0].click();