我得到的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 millisecondsBuild信息:版本:'2.52.0',修订:'4c2593c',时间:'2016-02-11 19:03:33‘系统信息:主机:'rsn-GA-78LMT-S2',ip:'127.0.1.1',os.name:'Linux',os.arch:’and 64‘,os.version:‘3.13.0-54-泛型’,java.version:‘1.7.0_101’会话ID: 17716ecc-ffe3 3-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、takesScreenshot=true、version=38.0.1}
发布于 2016-07-11 04:28:56
如果要获取具有文本History
的History
元素,请尝试使用带有ExpectedConditions.visibilityOfElementLocated
的linkText
来等待元素可见,如下所示:-
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement linkElement= wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("History")));
或者,如果要获取具有文本History
的History
元素,请尝试使用xPath
,如下所示:-
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement spanElement = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text() = 'History']")));
编辑的 :-如果通过鼠标在事件中看到此element
,请尝试使用Action
执行MouseOver
,如下所示:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement spanElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[text() = 'History']")));
Actions builder = new Actions(driver);
builder.moveToElement(spanElement).perform();
或
builder.mouse.mouseMove(((Locatable)spanElement).coordinates)
希望它能奏效。)
https://stackoverflow.com/questions/38306654
复制相似问题