有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何通过SeleniumWebDriver访问链接特定部分中的链接

enter image description here

在一个网页中,我看到三个h3标签,每个h3标签包含很少的链接

我的场景是:我想转到一个h3标签,只计算该部分和每个部分中的链接

有人能告诉我如何点击该特定部分的链接吗


共 (2) 个答案

  1. # 1 楼答案

    您可以这样做:

    List <WebElement> we = driver.findElements(By.xpath("//h3[text()='Quick Links ofHyderabad']/following::ul/a"));
    int noOfLinks = we.size();
    
    // To click on all the links just use a `for` loop
    for(WebElement w : we) {
        w.click();
    }
    
  2. # 2 楼答案

    根据需要自定义代码。应该是这样的:

    //Pick all div elements:
    List< IWebElement > elements = driver.FindElements(By.XPath(//div[contains(@class, 'description')]/h3));
    
    // Now use a forloop to go through each element and grab the data you need.
    String Data = elements.getText();
    
    // Split the Data using regex and get the count as per your html code