我正在与 Selenium 作斗争。
基本上我想单击以下元素来切换元素:
<div class="view-icon fadeIn" title="" data-placement="top" data-toggle="tooltip" data-original-title="Switch to List View">
<i class="fa fa-bars"></i>
</div>
它更改为:
<div class="view-icon fadeIn" title="" data-placement="top" data-toggle="tooltip" data-original-title="Switch to Tab View">
<i class="fa fa-list-alt"></i>
</div>
之后我只想填写表格并测试其输出。
我为单击此元素编写的方法:
public void clickAtListView() {
WebElement listView = driver.findElement(By.xpath("//div[@class='view-icon fadeIn']"));
listView.click();
}
但是,我得到:
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 50 milliseconds
对于为什么我会收到此异常有什么建议吗?
感谢您的回答!
更新
在我看来,当我将 Thread.sleep(10000); 放在前面时,列表元素就会显示:
但是,我仍然遇到异常;(
最佳答案
正如您发送的异常所示,该元素不可见,无法采取任何操作。
因此,您的代码
WebElement listView = driver.findElement(By.xpath("//div[@class='view-icon fadeIn']"));
获取隐藏元素(例如“View Tab”元素)。请尝试这个
WebElement listView = driver.findElement(By.xpath("//div[@data-original-title='Switch to List View']"));
关于java - Selenium - 单击切换元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24681827/