Tutorials Hut

  • Selenium WebDriver

       Selenium Introduction
       Benefits of Selenium
       Four components of Selenium
       Difference b/w Selenium IDE, RC & WebDriver
       Selenium WebDriver Architecture
       Background when user execute selenium code
       Download and Install Java
       Download and Install Eclipse
       Download Selenium WebDriver
       Selenium WebDriver Locators
       Selenium - Launch Browser
       Selenium WebDriver Waits
       Selenium- Implicit wait
       Selenium- Explicit wait
       Selenium- Fluent wait
       Selenium- Commonly used commands
       Selenium- findElement & findElements
       Selenium- Selenium-Handling check Box
       Selenium- Handling Radio button
       Selenium- Handling drop down
       Selenium- Take Screenshot
       Selenium- Handle Web Alerts
       Selenium- Multiple Windows Handling
       Selenium- Handle iframes
       Selenium- Upload a file
       Selenium- Download a file
       Selenium- Actions Class Utilities
       Selenium- Mouse Actions
       Selenium- Keyboards Events
       Selenium- Handle mouse hover Actions
       Selenium- Drag and Drop
       Selenium- Scroll a WebPage
       Selenium- Context Click / Right Click
       Selenium- Double Click
       Selenium- Desired Capabilities
       Selenium- Assertions
       Selenium- Exceptions and Exception Handling
       Selenium- Difference b/w driver.close() & driver.quit()
       Selenium- difference b/w driver.get() & driver.navigate()
       Selenium- JavascriptExecutor
       Selenium- Read excel file using Fillo API
       Selenium- Database Testing using Selenium
       Selenium- Read & write excel file using Apache POI
       Selenium- Read and Write csv file in Selenium
       Selenium- Dynamic Web Table Handling
       Selenium- Maven Integration with Selenium
       Selenium- Set up Logging using Log4j
       Selenium-Implement Extent Report



  • Handling Radio Button using Selenium WebDriver with Example

    In this tutorial we will learn how to interact with radio button in selenium.

    We can select or unselect radio buttons like checkbox using the click method .

    Handling Radio Button in Selenium WebDriver -Main

    We can select one radio button at a time. 

    We can also perform below checks before doing click operation on these

      • Verify Radio button or Checkbox is displayed on the webpage
      • Verify Radio button or Checkbox is enabled on the webpage
      • Verify the default selection of the Radio button or Checkbox

    Above scenarios can be verified using below predefined methods in selenium webdriver

      • isDisplayed()
      • isEnabled()
      • isSelected()

    Let’s take an example 

      1. Navigate to URL https://tutorialshut.com/demo-website-for-selenium-automation-practice/
      2. Verify above all the three scenarios for radio button ‘Male’ mentioned under Gender.
    How to handle Radio Button in Selenium WebDriver with Example

    Below is the webElement for Male button

    WebElement radioButtonMale = driver.findElement (By.id("male"));

    All the three methods will return boolean values either true or False.

    isDisplayed()

    radioButtonMale.isDisplayed () ⇒ returns   true  (Male radio button is present on the webpage ).

    isEnabled()

    radioButtonMale.isEnabled()  == > returns true  (Male radio button is enabled on the webpage)

    isSelected()

    radioButtonMale.isSelected()  == > returns false  (Male radio button is not already selected)

    Now Let us understand how to interact with Radio button using below scenario

    1. Open the Chrome Browser
    2. Navigate to URL https://tutorialshut.com/demo-website-for-selenium-automation-practice/
    3. In Section ‘Radio buttons’’ , 
    4. Verify ‘Male’ radio button is displayed , Print the output of isDisplayed().
    5. Verify ‘Male’ radio button is enabled , Print the output of isEnabled().
    6. Choose ‘Male’ radio button
    7. Verify ‘Male’ radio button is selected , Print the output of isSelected().
    8. Close the browser.

    Code Implementation

    package com.test;
    
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import junit.framework.Assert;
    
    public class HandlingRadioButton {
    
    public static WebDriver driver;
    
    public static void main(String[] args) throws InterruptedException {
    
    // Create a new instance of the Chrome driver
    
    System.setProperty("webdriver.chrome.driver", "D:\\Drivers\\chromedriver.exe");
    driver = new ChromeDriver();
    
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    
    // Launch the URL
    driver.get("https://tutorialshut.com/demo-website-for-selenium-automation-practice/");
    
    // Maximize the window
    driver.manage().window().maximize();
    
    WebElement radioButtonMale = driver.findElement(By.id("male"));
    
    // Verify ‘Male’ radio button is displayed , Print the output of
    // isDisplayed().
    Boolean flagDisplay = radioButtonMale.isDisplayed();
    Assert.assertTrue(flagDisplay);
    System.out.println("Male radio Button is displayed :" + flagDisplay);
    
    // Verify ‘Male’ radio button is enabled , Print the output of
    // isEnabled().
    Boolean flagEnable = radioButtonMale.isEnabled();
    Assert.assertTrue(flagEnable);
    System.out.println("Male radio Button is Enabled :" + flagEnable);
    
    // Choose ‘Male’ radio button
    radioButtonMale.click();
    
    // Verify ‘Male’ radio button is selected , Print the output of
    // isSelected().
    Boolean flagselected = radioButtonMale.isSelected();
    Assert.assertTrue(flagselected);
    System.out.println("Male radio Button is Selected :" + flagselected);
    
    // close the driver
    driver.close();
    
    }
    
    }
    
    



  • Selenium WebDriver Tutorials

       Selenium Introduction
       Benefits of Selenium
       Four components of Selenium
       Difference b/w Selenium IDE, RC & WebDriver
       Selenium WebDriver Architecture
       Background when user execute selenium code
       Download and Install Java
       Download and Install Eclipse
       Download Selenium WebDriver
       Selenium WebDriver Locators
       Selenium - Launch Browser
       Selenium WebDriver Waits
       Selenium- Implicit wait
       Selenium- Explicit wait
       Selenium- Fluent wait
       Selenium- Commonly used commands
       Selenium- findElement & findElements
       Selenium- Selenium-Handling check Box
       Selenium- Handling Radio button
       Selenium- Handling drop down
       Selenium- Take Screenshot
       Selenium- Handle Web Alerts
       Selenium- Multiple Windows Handling
       Selenium- Handle iframes
       Selenium- Upload a file
       Selenium- Download a file
       Selenium- Actions Class Utilities
       Selenium- Mouse Actions
       Selenium- Keyboards Events
       Selenium- Handle mouse hover Actions
       Selenium- Drag and Drop
       Selenium- Scroll a WebPage
       Selenium- Context Click / Right Click
       Selenium- Double Click
       Selenium- Desired Capabilities
       Selenium- Assertions
       Selenium- Exceptions and Exception Handling
       Selenium- Difference b/w driver.close() & driver.quit()
       Selenium- difference b/w driver.get() & driver.navigate()
       Selenium- JavascriptExecutor
       Selenium- Read excel file using Fillo API
       Selenium- Database Testing using Selenium
       Selenium- Read & write excel file using Apache POI
       Selenium- Read and Write csv file in Selenium
       Selenium- Dynamic Web Table Handling
       Selenium- Maven Integration with Selenium
       Selenium- Set up Logging using Log4j
       Selenium-Implement Extent Report













  • Leave a Reply

    Your email address will not be published. Required fields are marked *