Friday, March 11, 2016

Selenium JAVA and RUBY Locating Objects


 

 1. Text field


           username:   


    RUBY CODE:  # CODE FOR USERNAME TEXTBOX


                             driver.find_element(:id, "usernameid").send_keys ("test")


    JAVA CODE:   

                            driver.findElement(By.id("usernameid")).sendKeys("Selenium");

 2. Radio Button   

 

             Option 1  
             Option 2  
             Option 3  

  

   RUBY CODE: #    CODE FOR RADIO BUTTON       

            

                         driver.find_element(:name ,"radiobutton1").click      
                         driver.find_element(:name, "radiobutton2").click    
                         driver.find_element(:name, "radiobutton3").click


    JAVA CODE:    

                     
                          driver.findElement(By.name("radiobutton1")).click();
                       driver.findElement(By.name("radiobutton2")).click();
                       driver.findElement(By.name("radiobutton3")).click();

 3. CheckBox 


             

  RUBY CODE:  #   CODE FOR CHECKBOX


                           driver.find_element(:name, "checkthebox").click


   JAVA CODE:    
                     
                             driver.findElement(By.name("checkthebox")).click();

 4. Drop Down Box


           

  

  RUBY CODE:   CODE FOR DROPDOWN BOX


      Selenium::WebDriver::Support::Select.new(driver.find_element(:id =>"test")).select_by :text, 'Lion'

  JAVA CODE:    
  
                   Select drp = new Select(driver.findElement(By.id("test")));
               drp.selectByVisibleText("Non Reportable");

  

 5. ListBox


         

 RUBY CODE:  CODE FOR LISTBOX


Selenium::WebDriver::Support::Select.new(driver.find_element(:name=>"dropdown")).select_by :text, 'Volvo'

Selenium::WebDriver::Support::Select.new(driver.find_element(:name=>"dropdown")).select_by :text, 'Saab'


  JAVA CODE:     


                Select mulcountry = new Select(driver.findElement(By.name("dropdown")));
  mulcountry.selectByVisibleText("Volvo");
             mulcountry.selectByVisibleText("Saab"); 
mulcountry.selectByVisibleText("Mercedes");

 6. Links


          1.Yahoo


          2.Google


 RUBY CODE:   #   CODE FOR LINK

                   driver.find_element(:link,"1.Yahoo").click
                   # information - dont comment - browser back 
                   driver.navigate().back()

  JAVA CODE:   

                   driver.findElement(By.linkText("1.Yahoo")).click();
  //NAVIGATE BROSER BACK
             driver.navigate().back();

        

 7. Click the button to demonstrate Alert handle

                   
      


 RUBY CODE:   CODE FOR  HANDLING POPUP WINDOWS


                 driver.find_element(:xpath, "/html/body/font/button").click
                 alerttext=driver.switch_to.alert.text
                driver.switch_to.alert.accept


  JAVA CODE:   


               Driver.findElement(By.xpath("/html/body/font/button")).click();  
           String alertMessage = driver.switchTo().alert().getText();
  System.out.println(alertMessage);
  //CLICK ON ALERT OK BUTTON
  driver.switchTo().alert().accept();

 8. Table



StudentName Grade
John A
Mercury B

 9. Veritical Scroll bar


Vertical scroll bar

vertical scrollbar....

 10. Horizontal Scroll bar


Horizontal scrollbar....................

1 comment:

  1. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks Active Long Range RFID

    ReplyDelete