第一次,我能够找到该元素,但如果我重复相同的步骤并尝试找到该元素,那么我会收到以下错误:
org.openqa.selenium.ElementNotVisibleException:无法单击元素(警告:服务器确实>未提供任何堆栈跟踪信息) 命令持续时间或超时:172毫秒 构建信息:版本:'2.39.0',修订版:'ff23eac',时间:'2013-12-16 16:12:12' 系统信息:主机:'D-315009004',ip:'10 .101.160.72',os.name:'Windows 7',os.arch:'x86',> os.version:'6.1',java.version: '1.6.0_23' 会议ID:863c6fb7-ff23-4f18-9880-a63d36538bc8 驱动程序信息:org.openqa.selenium.ie.InternetExplorerDriver 功能[{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 =,takeScreenshot = true}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 在java.lang.reflect.Constructor.newInstance(未知来源)
以下是HTML代码段:
<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>
我试图点击close
<DIV id=ext-gen457 class="x-tool x-tool-close"> </DIV>
图标
答案 0 :(得分:4)
抛出错误,因为元素不可见。
您可以使用显式等待elemtent进行点击,然后点击它,如下所示:
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();
或者对隐形元素执行javascript,如下所示(但不能模仿真实用户):
WebElement element = driver.findElement(By.id("some_id"));
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);