4

I need my script to click on a button. So far I have tried this-

 driver.findElement(By.id("button_click")).click();

and HTML for this button is-

    <td class="Button">
<input class="btn" value="Click here to get started" name="button_click" onclick="this.form.action = '/servlet/servlet.Integration?lid=0076878676545487SVD2&eid=465124652J9ly&ic=1&retURL=%24848676854684y&wrapMassAction=1&scontrolCaching=1&linkToken=gituuiyiiuhjgd46etfjgioyyo8yo8ylihvTDNfLWhzdm5KLFlXWmtNR0po'; this.form.onsubmit = function() { return true }" title="page title" type="submit"/>
</td>

but it is not identifying the button right.

2 Answers 2

3

You try to search for your button by id, but your button has no id. The solution is to add an id to the button with the corresponding value:

    <td class="Button">
<input class="btn" value="Click here to get started" id="button_click" name="button_click" onclick="this.form.action = '/servlet/servlet.Integration?lid=0076878676545487SVD2&eid=465124652J9ly&ic=1&retURL=%24848676854684y&wrapMassAction=1&scontrolCaching=1&linkToken=gituuiyiiuhjgd46etfjgioyyo8yo8ylihvTDNfLWhzdm5KLFlXWmtNR0po'; this.form.onsubmit = function() { return true }" title="page title" type="submit"/>
</td>

If this is not an option, then you can search for elements by name, but then a list will be returned and you will need to choose the correct element from there, which is pretty simple if there is a single element.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I just spaced out that name thing
With pleasure, happy new year!
1

You can use

driver.findElement(By.Name("button_click")).click();

or

driver.findElement(By.CssSelector("input.btn:nth-of-type(X)")).click();

there is probably more than one input with 'btn' class in your page, so X would represent wich one of these buttons you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.