How to Click a Link by href value in Selenium WebDriver?

0 votes
How to Click a Link by href value in Selenium WebDriver?
Aug 14 in Selenium by Ujjwal
192 views

1 answer to this question.

0 votes

Hi Ujjwal, you can use following code snippet to click a link by its href value:

public void clickLinkByHref(String href) {
        List<WebElement> anchors = driver.findElements(By.tagName("a");
        Iterator<WebElement> i = anchors.iterator();

        while(i.hasNext()) {
            WebElement anchor = i.next();
            if(anchor.getAttribute("href").contains(href)) {
                anchor.click();
                break;
            }
        }
    }
answered Aug 14 by Abha
• 25,240 points

Related Questions In Selenium

0 votes
1 answer
0 votes
5 answers
0 votes
1 answer
0 votes
1 answer

How to open a browser window in full screen using Selenium WebDriver with C#

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,130 points
3,822 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,090 points
781 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,026 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
727 views
0 votes
1 answer

How to read a JS variable in Selenium Webdriver?

Hi Himanshu, its quite easy to access any ...READ MORE

answered May 7 in Selenium by Abha
• 25,240 points
719 views
0 votes
1 answer

How to click on a hyperlink using Selenium WebDriver?

Hi Jonathan, you can use click() method in ...READ MORE

answered May 29 in Selenium by Abha
• 25,240 points
358 views