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



  • How to do Drag and Drop using Actions in Selenium?

    This article will present you with a complete idea about how to drag and drop on a web page using Action Class in Selenium web driver.

    Drag and Drop in Selenium

    Few web applications have the ability to automate the functionality of drag and drop, i.e. drag web elements from one end and drop them on a destination area or element.

    In order to automate the drag and drop actions, We can use Actions Class used in Selenium WebDriver

    This is an action performed with a mouse when a user moves (drags) a web element and then places (drops) it into a destination

    Syntax for drag and drop.

    The Actions class has two methods that support Drag and Drop. Let’s study them-

    Actions.dragAndDrop(Sourcelocator, Destinationlocator).perform()

    Let’s see what happens internally when we use above code

      • clickAndHold(WebElement element) first performs click-and-hold without releasing  at the location of the source element
      • moveToElement(WebElement element) – Moves the mouse pointer to the middle of the web element without clicking.
      • release(WebElement element) – Releases the mouse which was previously pressed
      • build() – Generates a composite action containing all actions.
      • perform()-perform() method performs the actions

    We can use below syntax as well for drag and drop operations

    //Creating object of Actions class 

    Actions builder = new Actions(driver);

    //Building a drag and drop action

    Action dragAndDrop = builder.clickAndHold(fromElement)
    .moveToElement(toElement)
    .release(toElement)
    .build();

    Please go through the below example to understand the flow.

    Steps:

      1. Open chrome browser
      2. Navigate to URL “https://tutorialshut.com/demo-website-for-selenium-automation-practice/
      3. Drag webelement ‘Drag From’ object   to ‘Drog To’ object
      4. Close the browser
    Drag and Drop in Selenium Example

    //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 org.openqa.selenium.interactions.Actions;
    
    import org.openqa.selenium.support.ui.ExpectedConditions;
    
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    public class DragAndDrop {
    
    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/");
    
     // To get source locator
    
    WebElement source = driver.findElement(By.xpath("//button[text()='Drag FROM']"));
    
    // To get target locator
    
    WebElement target = driver.findElement(By.xpath("//button[text()='Drop TO']"));
    
    Actions action = new Actions(driver);
    
    //Building a drag and drop action and performing the action
    
    action.dragAndDrop(source, target).build().perform();
    
    }
    
    }
    



  • 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 *