Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to access Links and tables using partial match in selenium web driver

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 745
    Comment on it

    Dear user,

    In the last blog, I had explained, how we can access link using exact match, and now in this blog, I will guide you about how to access link using partial match in selenium web driver.

     

    Partial Match:

    We access links using a portion of their link text or we can say that partial match or we can locate elements of the link through by.partialLinkText () method. We can find elements using Inspect elements and get exact link in HTML code as below

     

    <html> 
    <body> 
    
    <a href = "http://www.linkedin.com/">Partial Hello </a> 
    
    </body> 
    </html>

    and we save this in HTML format with the name of misbah.html in any drive and after click 'Partial Hello' link text , this will navigate you linkedin.com page.

    For running this we write web driver code as below and access 'Partial Hello' link text and open linkedin.com page.

    public class misbah { 
    
     
       public static void main(String[] args){ 
              String baseUrl ="file:///C:/Users/misbah/Desktop/misbah.html"; 
              WebDriver driver; 
              System.setProperty("webdriver.gecko.driver", "D:\\Selenium\\Eclipse New setup(Neon)\\geckodriver.exe"); 
              driver= new FirefoxDriver(); 
               driver.get(baseUrl); 
               driver.findElement(By.partialLinkText("Hello")).click(); 
                             OR
                driver.findElement(By.partialLinkText("Partial")).click();
               String s=driver.getTitle(); 
               System.out.println("Title:"+s); 
               
    } 
    }

    In the above code first we make one object of firefox browser as a driver, using this object we get a base URL of HTML which is saved in Desktop,If we run above code in eclipse then linkedin.com open in firefox browser and we get the Output as Title: linkedin.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: