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

Java 如何通过SeleniumWebDriver访问链接特定部分中的链接,java,selenium-webdriver,Java,Selenium Webdriver,在一个网页中,我看到三个h3标签,每个h3标签包含很少的链接 我的场景是:我想转到一个h3标签,只计算该部分和每个部分中的链接 有人能告诉我如何单击该特定部分的链接吗?您可以这样做: List <WebElement> we = driver.findElements(By.xpath("//h3[text()='Quick Links ofHyderabad']/following::ul/a")); int noOfLinks = we.size(); // To click

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

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


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

您可以这样做:

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();
}
//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 
List-we=driver.findElements(By.xpath(“/h3[text()='hydrabad'Quick Links']/following::ul/a”);
int nooflings=we.size();
//要点击所有链接,只需使用'for'循环
for(WebElement w:we){
w、 单击();
}

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

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();
}
//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 
//选择所有div元素:
Listelements=driver.FindElements(By.XPath(//div[contains(@class,'description')]/h3));
//现在使用forloop遍历每个元素并获取所需的数据。
字符串数据=elements.getText();
//使用正则表达式分割数据,并根据html代码获取计数

你能分享一下html代码部分吗?海德拉巴的快速链接
@naazneen3264-我已经更新了我的答案。现在应该可以了。请在问题中发布HTML,格式正确,而不是图片。在将来的某个时候,图像将不再可用,这个问题的价值也将降低。谢谢