簡體   English   中英

如何通過selenium webdriver訪問鏈接特定部分的鏈接

[英]How to access links in the specific section of links through 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 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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM