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



  • Difference between findElement and findElements Commands with examples

    This article will present you with a complete idea about findElement()  and findElements() command in selenium WebDriver with examples

    Difference between findElement and findElements Commands in Selenium

    We will learn below topics in this article

    findElement() method

      • findElement() command is used to find a single element on the web page.
      • This command returns the object of the first matching element.
      • When element is not found using findElement() command , it will throw the exception ‘NoSuchElementException’
      • There are several ways for identifying a web element within the web page for e.g.  ID, Name, Class Name, Link Text, Partial Link Text, Tag Name and XPATH.

    Syntax- 

    WebElement element = driver.findElement(By.LocatorStrategy<br />(“Locator Value”));

    Locator Strategy can be  the following values.

      1. ID
      2. Name
      3. Class Name
      4. Tag Name
      5. Link Text
      6. Xpath

    Locator Strategy

    Syntax

    Description

    By IDdriver.findElement(By.id())Locate Element using ID
    By Namedriver.findElement(By.name())Locate Element using Name
    By Xpathdriver.findElement(By.xpath ())Locates Element using XPath 
    By CSSdriver.findElement(By.cssSelector())Locate Element using css selector
    By Tag Namedriver.findElement(By.tagName(<tagname))Locate Element using html Tag name
    By Link Textdriver.findElement(By.linkText())Locate Element using link text
    By Patial Link textdriver.findElement(By.partialLinkText())Locate Element using Partial link text
    By Class Namedriver.findElement(By.className())Locate Element using Class Name

    findElements() method.

    • findElements()  command is used to identify the list of web elements in the web page.
    • Return type of this method is the list of all the elements matching within the Page
    • If None of the elements is matching then this method will return an empty List.

    Syntax-

    List links  =driver.findElements(By.xpath(“//table/tr”));

    How to use Selenium findElement Command ?

    Scenario:

      1. Open the browser
      2. Navigate to https://tutorialshut.com/demo-website-for-selenium-automation-practice/
      3. Navigate to section “Sum of two numbers ‘A’ & ‘B’ (Input Form)”
      4. Find and enter values of A and B
      5. find element and click ‘Get Sum’ button
    findElement in Selenium WebDriver
    Code Implementation
    
    package com.test;
    
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class DemoFindElement {
    
    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");
    
    WebDriver 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();
    
    // find element using ID and enter value
    driver.findElement(By.id("num1")).sendKeys("1");
    driver.findElement(By.id("num2")).sendKeys("2");
    
    // find element using Xpath and click
    
    driver.findElement(By.xpath("//button[text()='Get Sum']")).click();
    
    // close the driver
    driver.close();
    
    }
    
    }
    

    How to use Selenium findElements Command?

    Scenario

      1. Open the browser
      2.  Navigate to https://tutorialshut.com/demo-website-for-selenium-automation-practice/
      3. Find the text of radio buttons and print on console.
    findElements in Selenium WebDriver

    Code Implementation

     
    package com.test;
    
    import java.util.List;
    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;
    
    public class DemoFindElements {
    
    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");
    
    WebDriver 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();
    
    // find elements for Radio button using Name
    List elements = driver.findElements(By.name("gender"));
    
    System.out.println("Number of elements:" + elements.size());
    
    for (int i = 0; i &lt; elements.size(); i++) {
    
    System.out.println("Radio button text:" + elements.get(i).getAttribute("value"));
    
    }
    
    // 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 *