【发布时间】:2016-11-13 09:12:23
【问题描述】:
我收到了ElementNotVisibileException,但此页面没有名称为“历史”的重复名称,但它确实有“通话历史”。谁能推荐最好的定位器来定位元素?
<li class="ui-widget ui-menuitem ui-corner-all ui-menu-parent" aria- haspopup="true" role="menuitem">
<a class="ui-menuitem-link ui-corner-all" href="javascript:void(0)">
<span class="ui-menuitem-text">History</span>
<span class="ui-icon ui-icon-triangle-1-e"></span>
</a>
错误
org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与之交互(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:122 毫秒构建信息:版本:'2.52.0 ',修订:'4c2593c',时间:'2016-02-11 19:03:33'系统信息:主机:'rsn-GA-78LMT-S2',ip:'127.0.1.1',os.name:' Linux',os.arch:'amd64',os.version:'3.13.0-54-generic',java.version:'1.7.0_101'会话 ID:17716ecc-ffe3-40f9-92a6-8a106acf478dDriver 信息:org. openqa.selenium.firefox.FirefoxDriver 功能 [{platform=LINUX,acceptSslCerts=true,javascriptEnabled=true,cssSelectorsEnabled=true,databaseEnabled=true,browserName=firefox,handlesAlerts=true,nativeEvents=false,webStorageEnabled=true,rotatable=false,locationContextEnabled=true,pplicationCacheEnabled=true , takeScreenshot=true, version=38.0.1}] atun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
【问题讨论】:
-
动作 c_history1 = new Actions(obj); WebElement visbilityhc = obj.findElement(By.xpath("//span[contains(text(),'Visibility')]")); WebElement vhistoryc = obj.findElement(By.xpath("//span[text() = 'History']")); WebElement vhcalls = obj.findElement(By.xpath("//span[(text() = 'Calls')]")); c_history1.moveToElement(visbilityhc).moveToElement(vhistoryc).moveToElement(vhcalls).click().build().perform();
-
如果您在最初发布问题后想要添加一些额外的详细信息(如上面的代码),而不是将其添加为评论,请继续编辑您的问题并将其添加到那里它可以被正确格式化并且更容易被未来的读者找到。
-
当您收到异常
ElementNotVisibleException时,这意味着您的元素已找到但不可见,因此无法与之交互。 Selenium 被设计为只与用户交互的元素,因为用户不能与不可见的元素交互,Selenium 也不会。从您的Actions代码来看,您似乎必须悬停几次然后单击。您是否尝试过添加断点并单步执行代码以查看会发生什么?它可能会帮助您找到问题。