When nosotros utter most drag too drop variety of tricky operations, We require to role Advanced User Interactions API of selenium WebDriver. It Is non thence uncomplicated too at the same fourth dimension non besides much hard. We require to write multiple syntax to perform drag too driblet action because you lot require to receive got multiple actions similar option the chemical ingredient past times clicking too holding mouse thence motion mouse to finish house too thence driblet chemical ingredient past times releasing mouse. Same matter you lot receive got to perform In webdriver.
Selenium WebDriver has Advanced User Interactions API (Actions class) to perform this variety of advanced user interactions for rich applications. We tin lavatory role Actions class too It dissimilar methods like dragAndDrop, clickAndHold, moveToElement, liberate too laid upward to composite all the actions of drag too driblet performance every bit shown In bellow given example. At final perform method volition perform the action.
package Testing_Pack; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.interactions.Action; import org.openqa.selenium.interactions.Actions; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; populace shape DragAndDrop { WebDriver driver = null; @BeforeTest populace void setup() throws Exception { driver = novel FirefoxDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.get(" "); } @Test populace void dragAndDrop() { //Locate chemical ingredient which you lot wants to drag. WebElement dragElementFrom = driver.findElement(By.xpath("//div[@id='dragdiv']")); //Locate chemical ingredient where you lot wants to drop. WebElement dropElementTo = driver.findElement(By.xpath("//div[@id='dropdiv']")); //Use Actions shape too Its members of WebDriver API to perform drag too driblet operation. Actions builder = novel Actions(driver); Action dragAndDrop = builder.clickAndHold(dragElementFrom) .moveToElement(dropElementTo) .release(dropElementTo) .build(); dragAndDrop.perform(); } }
Above event volition drag the small-scale foursquare chemical ingredient on big foursquare element. This Is only example. You tin lavatory role this event every bit a reference to perform drag too driblet performance In your spider web application. If you lot wants to past times specific X-Y pixel offset thence you lot tin lavatory sentiment THIS POST.
You tin lavatory honor to a greater extent than tutorials links HERE to root learning selenium WebDriver from basic.
In inward a higher house example, We receive got written full half dozen lines to drag too driblet an element. If you lot wants convert those half dozen lines In alone 1 business thence you lot tin lavatory create It every bit bellow. Replace bellow given 1 business alongside half dozen lines of inward a higher house example. It volition create same thing.
So this Is the agency to perform drag too driblet an chemical ingredient Using selenium WebDriver.
You tin lavatory honor to a greater extent than tutorials links HERE to root learning selenium WebDriver from basic.
In inward a higher house example, We receive got written full half dozen lines to drag too driblet an element. If you lot wants convert those half dozen lines In alone 1 business thence you lot tin lavatory create It every bit bellow. Replace bellow given 1 business alongside half dozen lines of inward a higher house example. It volition create same thing.
new Actions(driver).dragAndDrop(dragElementFrom, dropElementTo).build().perform();
So this Is the agency to perform drag too driblet an chemical ingredient Using selenium WebDriver.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/