Tuesday 17 January 2017

Webdriver Methods for Identifying elements

             A web application can contain many elements such as textbox, links, radio buttons, buttons, links, checkbox and drop down list. To locate element on web page webdriver provided findElement and findElements method.
             
             Page Elements : 
                                    1. Drop Down List.
                                    2. List Box.
                                    3. Web Table.
                                    4. Frame.
                                    5. Radio Button.
                                    6. Check Box.
                                    7. Image
                                    8. Link.
                                    9. Button.
                                   10. Text Box.
   
            Selenium Webdriver provides methods to uniquely identified an element in a HTML document during runtime.
            The various Webdriver methods which can be used to identify an element in GUI are as follows :

                 i. Id.
                ii. className.
               iii. tagName.
                iv. name.
                 v. linkText.
                vi. partialLinkText.
               vii. cssLocator.
              viii. Xpath.

1. Id :
         The id method uses the 'id' attribute to identify an HTML element.

        
   
         HTML Code of this element is :

         <input id="UserName" type="text" name="Uname" maxlength = "30"/>

         The Webdriver code to identify this element is :
     
          driver.findElement(By.id("UserName"));

2.  ClassName : 
          The className method uses the 'class' attribute to identify an HTML element.

        
   
         HTML Code of this element is :

         <input id="UserName" type="text" class="name" name="Uname" maxlength = "30"/>

         The Webdriver code to identify this element is :
     
          driver.findElement(By.className("name"));

3.  TagName : 
            The tagName method uses the 'tagName' attribute to identify an HTML element.
     
                                         


           User Name : <input id="UserName" type="text" name="Uname" maxlength = "30"/>
           <a href="www.google.com"> Know More </a>

          The Webdriver code to identify this element is :
     
          driver.findElement(By.tagName("a"));

       
4. Name :
           The Name method uses the 'name' attribute to identify an HTML element.

        
   
         HTML Code of this element is :

         <input id="UserName" type="text" class="name" name="Uname" maxlength = "30"/>

         The Webdriver code to identify this element is :
     
          driver.findElement(By.name("Uname"));
          

No comments:

Post a Comment