java - 调用click后如何导航到另一个页面?

标签 java htmlunit

我试图获取所有主要链接,然后单击它们并导航到该页面:

    WebClient client = new WebClient();

    HtmlPage page = client.getPage(url);

    // Get all links with a href of www.example.com/pages/1_

    List<HtmlAnchor> links = (List<HtmlAnchor>) page.getByXPath("//a[href='www.example.com/pages/1_*'");

    links[0].click();

调用click后,是否返回一个HtmlPage? (NetBeans 文档没有告诉我。)

XPath 是吗?表情看起来还好吗?

最佳答案

我不知道文档在 NetBeans 中如何工作,但文档都可以在线获取,并且 if you go to it ,你会看到返回类型是 <P extends Page>大多数时候可能是 HtmlPage,但也可能是 XmlPage 或类似的东西。

Simulates clicking on this element, returning the page in the window that has the focus after the element has been clicked. Note that the returned page may or may not be the same as the original page, depending on the type of element being clicked, the presence of JavaScript action listeners, etc.

关于java - 调用click后如何导航到另一个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2008600/

相关文章:

java - 使用 HtmlUnit 登录

java - Eclipse错误: Overlaps the location of other project

Java函数变量的默认值

java - 在 HtmlUnit 中设置代理

javascript - 尝试在 Jython 中使用 htmlunit 抓取 javascript 网站时出现问题

javascript - 从 url 导航页面时,HtmlUnitDriver 不加载 javascript

java - 如何对html内容中的特殊字符进行编码

java - 在其他数组中分离数组

java - RejectedExecutionHandler - CallerRunsPolicy 与 AbortPolicy

java - 这个 xpath 看起来正确吗?