Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I click on this element using XPATH in WebDriver with Java?

Here is the HTML:

<li>
<input type="checkbox" checked="" name="selectedMstrPrivGroupList[9].mstrAuthorities[0].status"/>
Add Dexter
</li>

How could this element be clicked in WebDriver? It is a check box. And I want to use XPath as I have close to 30+ check boxes in the page. So that I can create a generic method and pass only the WebElement. I tried the following but didn't work.

Driver.findElement(By.xpath("//input[contains(.,'Add Dexter')]")).click();
like image 563
Mike Avatar asked Oct 18 '25 10:10

Mike


1 Answers

If the checkbox next to "Add Dexter" is what you want to click on the page, you can use:

Driver.findElement(By.xpath("//li[contains(.,'Add Dexter')]//input[@type='checkbox']")).click();
like image 150
Rajiv Avatar answered Oct 19 '25 23:10

Rajiv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!