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();
3
  • Have you tried mouse hover first? Commented Jul 24, 2015 at 12:44
  • i think you should use WebDriverWait stackoverflow.com/questions/11736027/webdriver-wait-for-element Commented Jul 24, 2015 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 :) Commented Jul 24, 2015 at 14:23

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.