【发布时间】:2016-03-18 02:23:24
【问题描述】:
我正在尝试使用 Java 中 Selenium 的 HtmlUnitDriver 和 WebElement 类单击 Google 趋势上的“下载为 CSV”按钮。
我遇到的问题是,在您单击其他设置菜单按钮之前,该按钮被隐藏(不显示),但我无法使用 WebElement 单击该设置菜单按钮。
这是我的代码:
/**
* @args String, the term to search on Google Trends
*/
public static void main(String[] args)
{
//instantiate an HtmlUnitDriver
HtmlUnitDriver hud = new HtmlUnitDriver();
//navigate to the 90-day Google Trends page of the input term in args
hud.get("https://www.google.com/trends/explore#q=" + args[0] + "&date=today%203-m&cmpt=q&tz=Etc%2FGMT%2B8");
//set element to the first button to press
WebElement element = hud.findElement(By.id("settings-menu-button"));
//click the element
element.click();
}
我得到的错误是:org.openqa.selenium.ElementNotVisibleException: You may only interact with visible elements
但是设置菜单按钮是可见的?
这是我第一次制作这样的程序并使用这个库,所以感谢您的帮助。我还在学习。
【问题讨论】:
-
javascriptexecutor 无法在此处点击该元素?
标签: javascript java selenium selenium-webdriver