Selenium Webdriver finds an item (button)

I need my script to click on a button. While I tried it -

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

and HTML for this button -

    <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 he does not identify the button on the right.

+4
source share
2 answers

You are trying to find your button on id, but your button does not have id. The solution is to add a button idto the button with the appropriate 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, you can search for items name, but then the list will be returned, and you will need to select the correct item, which is pretty simple if there is one item.

+3
source

you can use

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

or

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

, "btn" , X , .

+1

Source: https://habr.com/ru/post/1665344/


All Articles