Search code examples
javahtmlseleniumhref

How do I click on this link using Selenium in Java


I am on this website and I am trying to click on Batch search using the selenium webDriver: https://metlin.scripps.edu/landing_page.php?pgcontent=mainPage

The HTML code for the link is:

<a href="landing_page.php?pgcontent=batch_search" style="color:white; font-weight:bold; font-size:13px">Batch Search </a >

My attempted solution is:

driver3.findElement(By.linkText("Batch Search")).click();   

However, this doesn't seem to work. Any ideas?


Solution

  • I like to use css selectors, which would be:

    String selector = "a[href=\"landing_page.php?pgcontent=batch_search\"]";
    driver3.findElement(By.cssSelector(selector)).click()