Psl*_*Psl 16 java selenium xpath
我有一个HTML href
链接
<a href="/docs/configuration">App Configuration</a>
Run Code Online (Sandbox Code Playgroud)
使用Selenium我需要点击链接.目前,我使用下面的代码 -
Driver.findElement(By.xpath("//a[text()='App Configuration']")).click();
Run Code Online (Sandbox Code Playgroud)
但它没有重定向到页面.我也试过下面的代码 -
Driver.findElement(By.xpath(//a[@href ='/docs/configuration']")).click();
Run Code Online (Sandbox Code Playgroud)
但这是抛出异常 -
org.openqa.selenium.ElementNotVisibleException:元素当前不可见,因此可能无法与命令持续时间或超时交互:13毫秒
链接可见,页面已完全加载.我不知道我的代码有什么问题.
Sar*_*a G 21
webDriver.findElement(By.xpath("//a[@href='/docs/configuration']")).click();
Run Code Online (Sandbox Code Playgroud)
以上行正常.请在href之后删除空格.
该元素在页面中是否可见,如果元素不可见,请向下滚动页面然后执行单击操作.
使用
driver.findElement(By.linkText("App Configuration")).click()
Run Code Online (Sandbox Code Playgroud)
其他方法将是
JavascriptLibrary jsLib = new JavascriptLibrary();
jsLib.callEmbeddedSelenium(selenium, "triggerMouseEventAt", elementToClick,"click", "0,0");
Run Code Online (Sandbox Code Playgroud)
要么
((JavascriptExecutor) driver).executeScript("arguments[0].click();", elementToClick);
Run Code Online (Sandbox Code Playgroud)
有关详细解答,请查看此帖子
归档时间: |
|
查看次数: |
142104 次 |
最近记录: |