2

How can I select the following check-box, if I only have these attributes?

<input style="font-size: 30%" onclick="remove_descriptions( this );" onchange="remove_descriptions( this );" type="checkbox">

I have tried several ways using xPath but I have had no luck.

driver.findElement(By.xpath("//input[@type='checkbox']"));

UPDATE

I cannot edit the HTML or CSS files.

7
  • are there other checkboxes at page? Commented Jul 16, 2015 at 19:11
  • Yes there is a couple. Commented Jul 16, 2015 at 19:15
  • add extra class to your checkbox and findElement(By.className("myCheckbox")) Commented Jul 16, 2015 at 19:18
  • I would but I do not have access. Commented Jul 16, 2015 at 19:19
  • 1
    add some more of the surrounding html, from there it will be a lot easier to help you out by providing a working xpath. Commented Jul 16, 2015 at 19:38

1 Answer 1

2

If you want keep using XPath to select it, a good idea is find a tag with an ID that your checkbox are inside and start the selector using this reference. An example:

<div id="my-id">
   <input type="checkbox" class="my-class">
   <input type="checkbox">
   <input type="checkbox" class="my-class">
</div>

The selector to find the 3rd element:

driver.findElement(By.xpath("(//div[@id='my-id']/input)[3]"));

The selector to find the 2nd element with class "my-class":

driver.findElement(By.xpath("(//div[@id='my-id']/input[@class='my-class'])[2]"));

If necessary, you can try find it by label and select ancestors tags with xpath parent. After, you easily can navigate children tags by xpath

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.