Partial link text is just like an linkText() method which how the method does. But, in one small changes in between with this two. While using linkText() method, user should provide the value or input complete text of the hyperlinks text which is displayed in the front end web page. Whereas, partialLinkText() user should provide the partial text which is displayed on the front end web page.
Example : For linkText() method, In Facebook login page user need to provide the Forgot your password? full text to locate the web element.
For partialLinkText() method, In facebook login page user need to provide the part of the words from the hyperlink -> Forgot your. Just provide the partial sentence of the hyperlinks.
Code:
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.chrome.*; public class linktext { private static WebDriver driver = null; public static void main(String[] args){ //setting the property for chrome browser and to invoke the chrome browser System.setProperty("webdriver.chrome.driver", "C://Selenium//chromedriver.exe"); WebDriver driver=new ChromeDriver(); driver.get("http://www.facebook.com"); //Retrieve and click the partialLinkText on the front end of the webpage WebElement fbpartialLinkText = driver.findElement(By.linkText("Forgot your")); fbpartialLinkText.click(); //Printing the result into the console System.out.println("Successfully clicked the link text of " +fbpartialLinkText); } }
Output:
Successfully clicked the link text of [[ChromeDriver: chrome on XP (65d313d7883399824e0e578e458625bc)] -> partial link text: Forgot your password?]