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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 563
    Comment on it

    Dear User,

    In the last blogs I had explained about Regular expressions, now In this blog, I will explain you about how we can access links and tables using selenium web driver.

    We can access links an exact match or partial according to test scenarios in automated code through selenium web driver.

     

    Exact match:

    We can access links with exact match or we can locate elements of the link through by.linkText () 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/"> Hello </a>
    
    </body>
    </html>

    and we save this in HTML format in any drive and after click 'Hello' link text , this will navigate you linkedin.com page.

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

     

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    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.LinkText("Hello")).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 baseurl 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: