Subscribe Us

How To Click On Link In Selenium Webdriver

.
Questions : How to Click On Link In Selenium Webdriver Using Java ?

Answer :
There are two way to click on link
1) linkText()
2) PartialLinkText()

linkText ()
Link text method in selenium used to click on link. in selenium accessing link using exact Text Matchwe use By.linkText() methods. In case there are two link with same text , then in this case linktext () method will access only the first link.

Example 
Example of link text method is given below
 driver.findElement(By.linkText("Forgotten account?")).click();

Selenium Code to click on Link Using Link Text Method

Code :


package automation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LinkTextMethod 
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Software\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
driver.findElement(By.linkText("Forgotten account?")).click();
}
}


Partial Link Text()
Partial Link Text is used to click on link . this method is used to access the link by portion text of link .In case if there are two link with same name (after the specify partial link text ) in that cases it will access only first link .

Example
Example of Partial Link Text method is given below  
driver.findElement(By.partialLinkText("gotten")).click();

Selenium Code to click on Link Using partial Link Text Method

Code :

package automation;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class ClickOnLink 
{
public static void main(String[] args
{
System.setProperty("webdriver.chrome.driver", "C:\\Software\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
driver.findElement(By.partialLinkText("gotten")).click();
}
} 

In this tutorial we learn how to Click on link in selenium webdriver with various types .Hope this tutorial helpful for you đŸ˜Š

Thanks & Regards 
Sandeep Yadav

Related Post

  • How to Click on check box in selenium webdriver 
  • How to select the radio button in selenium webdriver 
  • How to delete cookies in selenium webdriver 
  • How to select the value from the dropdown

Important Tags:
how to click on link using selenium , Link text Method in selenium , How t click on link in selenium webdriver using java , how to click on link text in selenium 
How To Click On Link In Selenium Webdriver 



Post a Comment

0 Comments