Zach Johnson Zach Johnson - 1 year ago 67 Question

Selenium click on dynamic id'd checkbox

I am having a bit of trouble with this. I am trying to click on a check box with an ID that is different each page load.

This is the code I have that doesn't work:

Dim SegmentData As IWebElement = driver.FindElementByXPath("//*[starts-with(@id, 'gwt-uid-5')]")

This is the xpath for the element:


The last 3 digits (324 in this case) are what change.

Nothing I try seems to work for me as each click attempt always fails.

Here is the exception thrown in this instance:

Exception thrown: 'OpenQA.Selenium.ElementNotVisibleException' in WebDriver.dll

And here is the HTML for the checkbox:

<div class="spee-f">
<span class="gwt-CheckBox">
<input type="checkbox" value="on" id="gwt-uid-5324" tabindex="0">
<label for="gwt-uid-5324">Segment statistics by month</label>

Answer Source

Try following XPath and let me know it error still occurs:

//span[label[text()="Segment statistics by month"]]/input[@type="checkbox"]