Saturday, June 22, 2024

Handling Radio Button

 

Handling Radio Button: 

Common Actions:

  1. Click Radio button
  2. Check if 'Radio button' element is displayed
  3. Check if 'Radio button' element is enabled
  4. Check if 'Radio button' is selected

Example Code:

package WebelementsBasics;

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class RadioBtnBasics {

 

            public static void main(String[] args) throws InterruptedException {

                        //open chrome browser

                        System.setProperty("webdriver.chrome.driver", ".\\Drivers\\chromedriver.exe");

                        WebDriver  driver =  new ChromeDriver();

 

                        // open url  file:///C:/brahma/Practise/qtp%20practise/web%20apps/ALL%20Web%20objects.html

                        driver.get("file:///C:/brahma/Practise/qtp%20practise/web%20apps/ALL%20Web%20objects.html");

 

                        // click  'Male' radio btn using id

                        WebElement   maleRadioBtnEle = driver.findElement(By.id("maleid"));

                        maleRadioBtnEle.click();

 

                        Thread.sleep(3000);

 

                        //  check "male" radio btn is selected

                        boolean  isSelected  =  maleRadioBtnEle.isSelected();

                        //                             true

                        //

                        System.out.println("isSelected="+isSelected); //

                        //                isSelected= true

 

                        // check 'Female' radio btn is selected using id

                        WebElement femaleRadioBtnEle= driver.findElement(By.id("femaleid"));

                        isSelected = femaleRadioBtnEle.isSelected();

                        //           isSelected2 =  false         

 

                        //                            

 

                        System.out.println("isSelected="+isSelected);//

 

                        // HW  check 'Male' radio btn is displayed

 

                        // HW check 'Male' radio btn is enabled

 

 

                        //  get  id, type  attribute values for 'male' radio btn              

                        String attrID= maleRadioBtnEle.getAttribute("id");

                        // maleid

;                      

                        System.out.println("idVal="+attrID);

 

                        //                  maleid

 

 

                        ///

                       

                        String type=  maleRadioBtnEle.getAttribute("type");

                        //                                radio

                        System.out.println("type="+  type);

                        //                                                          type=radio

 

 

                        //Hw click Female Radio btn using id

 

                        // HW get  name, id attribute values for 'female' radio btn               

 

 

 

 

 

            }

 

}

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...