Reputation: 31
This is the button that I want to clicked. I want to check this button by writing automation scripts in selenium web driver by using Java.
The following is the code for the button.
<label class="toggle" style="font-size:13px">
<input type="checkbox" name="checkbox-IsEFR" id="checkbox-IsEFR">
<i data-swchon-text="Yes" data-swchoff-text="No"></i>Is Enable for Rules
</label>
Please help me since I am new to automation scripts writing. I wrote the script for check box but it is not working. The following, I have attached the my scripts and the error generated.
@When("^clicks on enable for rules$")
public void clicks_on_enable_for_rules() throws Throwable {
driver.findElement(By.name("checkbox-IsEFR")).click();
}
The error that I received.
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 209 milliseconds Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58' System info: host: 'DELL_I5', ip: '192.168.1.33', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_77' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=46.0, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 03695ef8-bd24-49d6-b8a1-6687e3d0375c at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:327) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:85) at mCollector.features.StepDefinitions_mCollector.clicks_on_enable_for_rules(StepDefinitions_mCollector.java:61) at ✽.And clicks on enable for rules(C:/Users/Admin/workspace/MStudio - eBilling/src/mCollector/features/mCollector.feature:12) Caused by: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'DELL_I5', ip: '192.168.1.33', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_77'
Driver info: driver.version: unknown at .fxdriver.preconditions.visible(file:///C:/Users/Admin/AppData/Local/Temp/anonymous546390466745105063webdriver-profile/extensions/[email protected]/components/command-processor.js:10092) at .DelayedCommand.prototype.checkPreconditions_(file:///C:/Users/Admin/AppData/Local/Temp/anonymous546390466745105063webdriver-profile/extensions/[email protected]/components/command-processor.js:12644) at .DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/Admin/AppData/Local/Temp/anonymous546390466745105063webdriver-profile/extensions/[email protected]/components/command-processor.js:12661) at .DelayedCommand.prototype.executeInternal_(file:///C:/Users/Admin/AppData/Local/Temp/anonymous546390466745105063webdriver-profile/extensions/[email protected]/components/command-processor.js:12666) at .DelayedCommand.prototype.execute/<(file:///C:/Users/Admin/AppData/Local/Temp/anonymous546390466745105063webdriver-profile/extensions/[email protected]/components/command-processor.js:12608)
Upvotes: 0
Views: 480
Reputation: 2044
You can search by xpath in Selenium, using something like:
driver.find_element_by_xpath(".//*[contains(text(), 'Is Enable for Rules')]").click()
Upvotes: 0
Reputation: 371
The Error is : "ElementNotVisibleException: Element is not currently visible and so may not be interacted with.."
There may be multiple reason of occurring this error but the strongest possibility is that:
The element is not loaded on the page and your code is trying to click it. To handle this you can put wait statement in your code. A global wait can be imposed by putting implicit wait driver.manage().timeouts().implicitlyWait(5000L, TimeUnit.SECONDS);
or you can try putting explicit wait statement before performing the click activity.
Try the solution and I think it'll resolve your issue.
Upvotes: 1
Reputation: 50819
You can use explicit wait and ExpectedConditions to wait for the checkbox to be visible
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("checkbox-IsEFR"))).click();
This will wait up to 10 seconds for the element to be visible before clicking on it.
Upvotes: 1