Selenium webdriver org.openqa.selenium.ElementNotVisibleException:无法单击元素";在WebDriver(IE9)中

Selenium webdriver org.openqa.selenium.ElementNotVisibleException:无法单击元素";在WebDriver(IE9)中,selenium-webdriver,Selenium Webdriver,这是我第一次能够找到元素,但如果我重复相同的步骤并尝试找到元素,则会出现以下错误: 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',o

这是我第一次能够找到元素,但如果我重复相同的步骤并尝试找到元素,则会出现以下错误:

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,IgnoreZoomSet=false,ie.ensureCleanSession=false,>browserName=internet explorer,enableElementCacheCleanup=true,unexpectedAlertBehaviour=Disease,>version=9,ie.usePerProcessProxy=false,CSSSelectorEnabled=true,>ignoreProtectedModeSettings=false、 requireWindowFocus=false,handlesAlerts=true,>initialBrowserUrl=“”,ie.forceCreateProcessApi=false,nativeEvents=true,browserAttachTimeout=0,>ie.BrowserCommandLineSwitchs=,takesScreenshot=true}] 位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 位于sun.reflect.NativeConstructorAccessorImpl.newInstance(未知源) 位于sun.reflect.delegatingConstructor或AccessorImpl.newInstance(未知源) 位于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">&nbsp;</DIV>
        <SPAN id=ext-gen461 class=x-window-header-text>View/Edit QC</SPAN>
      </DIV>
    </DIV>
  </DIV>
</DIV>

查看/编辑QC

当我试图点击
close
图标,该图标是

时,由于元素不可见,因此抛出错误

您可以使用explicit wait for ELEMENT可单击,然后按如下方式单击它:

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,如下所示(但不模仿真实用户):


由于元素不可见,因此引发错误

您可以使用explicit wait for ELEMENT可单击,然后按如下方式单击它:

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,如下所示(但不模仿真实用户):


您好,谢谢您的回复。我尝试了您的代码,但在执行之后,我得到了“org.openqa.selenium.TimeoutException:”异常,在等待元素可单击10秒后超时:消息。手动单击元素需要多长时间?如果超过10秒,则相应地增加我上述代码第一行的超时。手动操作不会花费太多时间。当应用程序运行缓慢时,最多需要2到3秒。虽然我尝试了40秒,但仍然得到了响应“org.openqa.selenium.TimeoutException:在等待元素可点击的40秒后超时:”我甚至尝试了修改的脚本,但仍然不起作用。我找到了替代方法,即
Actions action action=new Actions(driver);action.sendKeys(key.ESCAPE).build().perform();
我知道这也不是一个正确的答案,但使用“Escape”,我可以关闭它。无论如何,谢谢你的建议。嗨,谢谢你的回复。我尝试了你的代码,但在执行后,我得到了“org.openqa.selenium.TimeoutException:“exception with”,在等待元素可点击10秒后超时:“消息。手动单击元素需要多长时间?如果超过10秒,则相应地增加我上述代码第一行的超时。手动操作不会花费太多时间。当应用程序运行缓慢时,最多需要2到3秒。虽然我尝试了40秒的时间,但仍然获得了成功。”“org.openqa.selenium.TimeoutException:在等待元素可点击的40秒后超时:”我甚至尝试了修改的脚本,但仍然不起作用。我找到了替代方法,即
Actions action action=new Actions(driver);action.sendKeys(key.ESCAPE).build().perform()
我知道这也不是一个正确的答案,但使用“Escape”,我可以关闭它。感谢您的建议。请将html发布在此处HI,PF html发布在此处:
查看/编辑QC
在上面的html中,我正在尝试查找“close”“图标使用
class=x-tool x-tool-close
。您是否尝试过
div
close
id使用
By.id()
By.className()
?您也可以发布您尝试过的内容请将html发布在此处hi,PF html发布在此处:
查看/编辑QC
在上面的html中,我正在尝试查找“close”图标使用
class=x-tool x-tool-close
。您是否使用
By.id()
By.className()
尝试过
div
关闭id?您也可以发布您尝试过的内容