Ksingh Ksingh - 7 months ago 9
HTML Question

Selenium can't find locator

See this imageI have a list of checkboxes which can be scrollable, but I can't find the actual locator. This is the HTML:

<a class="collection-item" href="#!" disabled="">
<span>
<input id="3" class="filled-in checkbox-orange" type="checkbox"/>
<label for="3"/>
</span>
<span for="3"> 3 AM- 4 AM </span>
</a>


I have tryed this but it's not working:

driver.findElement(By.cssSelector("a.collection-item").id("3"));
// or
driver.findElement(By.xpath(".//*[@id='time']/a[3]")).click();
// or
Actions builder = new Actions(driver);
builder.moveToElement(we1).click().build().perform();

Answer

If you are getting "Element is not currently visible and so may not be interacted with Command" exception, you are probably setting your element display or visibility property to hidden in one of your css classes. To fix it, do this.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('3').setAttribute('display', 'block')");
js.executeScript("document.getElementById('3').setAttribute('visibility', 'visible')");
// Finally, click your checkbox.
driver.findElement(By.id('3')).click();