Selenium - 单击切换元素 [英] Selenium - click on a toggle element
问题描述
我正在使用selenium。
I am struggeling with selenium.
基本上我想点击以下元素来切换元素:
Basically I want to click the following element to toggle the element:
<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>
之后我只想填写表格并测试其输出。
After that I just want to fill in the form and test its output.
我为单击此元素编写的方法:
The method I wrote for clicking this element:
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
为什么我得到这个例外的任何建议?
Any recommendations why I get this exception?
我感谢您的回答!
更新
在我看来我在之前输入 Thread.sleep(10000);
时显示列表元素:
It seems to me that the list element gets shown when I put Thread.sleep(10000);
before:
然而,我仍然得到异常;(
However, i still get the exception ;(
推荐答案
由于您发送的异常表示该元素不可见,无法采取任何行动。
As your sent exception said the element is not visible to take any action.
因此,您的代码
WebElement listView = driver.findElement(By.xpath("//div[@class='view-icon fadeIn']"));
隐藏element(例如View Tab元素)。请t这一个
gets a hidden element (E.g. "View Tab" element). Please try this one
WebElement listView = driver.findElement(By.xpath("//div[@data-original-title='Switch to List View']"));
这篇关于Selenium - 单击切换元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!