Reputation: 221
For the first time, I am able to find the element but if I repeat the same step and try to find the element then I am getting following error:
org.openqa.selenium.ElementNotVisibleException: Cannot click on element (WARNING: The server did >not provide any stacktrace information) Command duration or timeout: 172 milliseconds Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12' System info: host: 'D-315009004', ip: '10.101.160.72', os.name: 'Windows 7', os.arch: 'x86', >os.version: '6.1', java.version: '1.6.0_23' Session ID: 863c6fb7-ff23-4f18-9880-a63d36538bc8 Driver info: org.openqa.selenium.ie.InternetExplorerDriver Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0, >enablePersistentHover=true, ignoreZoomSetting=false, ie.ensureCleanSession=false, >browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, >version=9, ie.usePerProcessProxy=false, cssSelectorsEnabled=true, >ignoreProtectedModeSettings=false, requireWindowFocus=false, handlesAlerts=true, >initialBrowserUrl="", ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, >ie.browserCommandLineSwitches=, takesScreenshot=true}] 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)
Following is the HTML code snippet:
<DIV style="Z-INDEX: 9003; POSITION: absolute; WIDTH: 1000px; DISPLAY: block; VISIBILITY: visible; TOP: 76px; LEFT: 183px" id=ext-comp-1067 class=" x-window">
<DIV class=x-window-tl>
<DIV class=x-window-tr>
<DIV class=x-window-tc>
<DIV style="MozUserSelect: none; KhtmlUserSelect: none" id=ext-gen452 class="x-window-header x-unselectable x-window-draggable" unselectable="on">
<DIV id=ext-gen457 class="x-tool x-tool-close"> </DIV>
<SPAN id=ext-gen461 class=x-window-header-text>View/Edit QC</SPAN>
</DIV>
</DIV>
</DIV>
</DIV>
where I'm trying to click on close
icon which is <DIV id=ext-gen457 class="x-tool x-tool-close"> </DIV>
Upvotes: 2
Views: 19862
Reputation: 14046
The error is thrown because element isn't visible.
You can use explicit wait for elemtent to be clickable and then click on it like following:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
//or try: WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("someid")));
element.click();
Or execute javascript on invisible element like following(but which doesn't mimic real user):
WebElement element = driver.findElement(By.id("some_id"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
Upvotes: 4