How to click a link whose href has a certain substring in Selenium?

前端 未结 4 1471
攒了一身酷
攒了一身酷 2020-12-07 18:51
4条回答
  •  生来不讨喜
    2020-12-07 19:51

    With the help of xpath locator also, you can achieve the same.

    Your statement would be:

    driver.findElement(By.xpath(".//a[contains(@href,'long')]")).click();
    

    And for clicking all the links contains long in the URL, you can use:-

    List linksList = driver.findElements(By.xpath(".//a[contains(@href,'long')]"));
    
    for (WebElement webElement : linksList){
             webElement.click();
    }
    

提交回复
热议问题