Friday 13 December 2013

Webdriver : All Possible ways for DragAndDrop

In WebDriver we have different ways for performing DragAndDrop operations.
Following are the possible ways for handling DragAndDrop

METHOD 1:

// Create Actions object passing in a WebDriver object
            Actions builder = new Actions(driver);

            // Chain some calls together and call build
            Action dragAndDrop = builder.clickAndHold(someElement)
            .moveToElement(otherElement)
            .release(otherElement)
            .build();

            // Perform the actions
            dragAndDrop.perform();
METHOD 2:
            WebElement source = driver.findElement(By.id("draggable"));
            WebElement target = driver.findElement(By.id("droppable"));
            Actions builder = new Actions(driver);
            builder.dragAndDrop(source, target).perform();
            try{
            assertEquals("Dropped!", target.getText());
            } catch (Error e) {
            verificationErrors.append(e.toString());
            }

METHOD 3:
Actions builder = new Actions(driver);
           builder.clickAndHold(SOURCEELEMENT)
           .moveByOffset(10, 50).release().perform(); 
 
METHOD 4:
Action dragAndDrop = builder.dragAndDropBy(SourceElement, 10, 20)
               .build();
                dragAndDrop.perform();




Please do comment for any queries

Wednesday 11 December 2013

All possible ways for handling frames / iframes using Selenium Webdriver

Following are the possible ways for handling Frames

1.If Frame is having the element properties like name/value
webdriver.switchTo().frame("frame name/value");
2.If Frame is having index
webdriver.switchTo().frame(index);
3.If the Frame Properties or changing dynamically / if u want to perform using frame xpath / css path
webdriver.switchTo().frame(webdriver.findElement(By.xpath(elementxpath));
webdriver.switchTo().frame(webdriver.findElement(By.cssSelector(elementcsspath));
Note: finally if you want to make operation out of the frame first you need get out of the frame following is the statement for that
driver.switchTo().defaultContent();

Please do comment on any queries

Other Popular posts:

Handling table tags using Selenium Webdriver

While working with dynamic tables using Selenium Webdriver, following procedure could help you 


int tdSize = webdriver.findElements(By.xpath("//table[indexValue/xpathFromitsParentElenment]//td")).size();        for(int i=1;i<tdSize;i++)        {           if(webdriver.findElements(By.xpath("//table[indexValue/xpathFromitsParentElenment]//td[i]//div")).size()!=0)
           //if we have the div element in side td tag then the condition get passed
            {
              System.out.println("Data in <div> tag:"+webdriver.findElement(By.xpath("
//table[indexValue/xpathFromitsParentElenment]//td[i]//div")).getText());
          //for printing the content in the inner div tag
        }
           //if we have the div element in side td tag then the condition get passed
            {              System.out.println("Data in <div> tag:"+webdriver.findElement(By.xpath("//table[indexValue/xpathFromitsParentElenment]//td[i]//div")).getText());
          //for printing the content in the inner div tag
        }
          //for printing the content in the inner div tag        }}


Please do comment on any queries



How to install Maven on Windows

All possible ways for handling DragAndDrop using Selenium

All Possible ways for switching frames in Selenium

Automating tables tags using Selenium


Selenium Webdriver Integration with JBheave (BDD)