Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)

JxBrowser DOM API provides functionality that can be used for finding HTML elements on loaded web page by different conditions. The following sample code demonstrates how to find all HTML elements by specified tag name: (JxBrowser DOM API提供的功能可用于在不同条件下查找已加载网页上的HTML元素。以下示例代码演示了如何通过指定的标记名查找所有HTML元素:)

List<DOMElement> divs = document.findElements(By.tagName("div"));

If you need to find only first HTML element in the document use the following approach: (如果只需要在文档中找到第一个HTML元素,请使用以下方法:)

DOMElement div = document.findElement("myId"));

In general you can search for HTML elements using different conditions: (通常,您可以使用不同的条件搜索HTML元素:)

DOMElement element = document.findElement("myId"));
DOMElement element = document.findElement(By.tagName("div"));
DOMElement element = document.findElement(By.className("myClass"));
DOMElement element = document.findElement("myName"));
DOMElement element = document.findElement(By.xpath("//textarea"));
DOMElement element = document.findElement(By.cssSelector("#root"));