0

I have a toggle element in a webpage. Using selenium i have to toggle right .Am not sure how it can be done using selenium

Actualy I need to click the following element to toggle

<div class="right">
<input id="app_in" class="cmn-toggle cmn-toggle-round" type="checkbox" value="false">
<label class="preference" tabindex="2" data-preference="inFlag" data-guid="26865MS" for="app_in"></label>
</div>

i tried following code to click the checkbox but getting "Element is not currently visible and so may not be interacted with" error

 driver.findElement(By.id("app_in")).click();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Psl
  • 3,830
  • 16
  • 46
  • 84
  • Have you tried [mouse hover](http://stackoverflow.com/questions/15339311/how-to-do-mouse-hover-using-selenium-webdriver-in-firefox-19) first? – lloyd Jul 24 '15 at 12:44
  • i think you should use WebDriverWait http://stackoverflow.com/questions/11736027/webdriver-wait-for-element – Sirim Jul 24 '15 at 13:31
  • Honestly, this question isn't really about toggling an element. It is about not understanding why an element is not visible. And frankly, you show no effort in understanding your error message. The title is misleading, and the question is lacking research. This will not be helpful for future readers wondering how to actually toggle an element. So i have downvoted it. If you fix it, I will change it to an upvote :) – jumps4fun Jul 24 '15 at 14:23

1 Answers1

2

One possible solution here could be to wait for the element to become visible:

WebDriverWait wait = new WebDriverWait(webDriver, 10);
WebElement element wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("app_in")));

element.click();

If it does not help, try clicking the element through javascript:

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195