Friday, December 21, 2012

How to click on a element with specific Text

How we will click on a element(Link/button/any element) with a specific Text.

In the below example i open Yahoo Website and look for an element called "Mail", if it found it clicks on the link else it reports Exception saying String not found.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ClickLinkByText
    public static void main(String[] args)
        String s_URL="";
        String s_SearchLink="Mail";
        WebDriver driver=new FirefoxDriver();
        catch(Exception e)
            System.out.println("Searched string not found");

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.