微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 在Java中使用Selenium与wep页面交互时遇到问题

我正在尝试使用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:您只能与可见元素进行交互

但是设置菜单按钮是否可见?

这是我第一次制作这样的程序并使用这个库,所以感谢您的帮助.我还在学习.

解决方法:

你能试试吗?

public static void main(String[] args)
{
    //instantiate an HtmlUnitDriver
    HtmlUnitDriver hud = new HtmlUnitDriver();
    wait = new webdriverwait(hud , 120);
    //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");
       wait.until(ExpectedConditions.presenceOfElementLocated(By.id("settings-menu-button")).click();

   }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐