TESTEVERYTHING

Wednesday, 17 June 2015

Difference between action.build().perform() and action.perform()


In Webdriver, handling keyboard events and mouse events (including actions such as Drag and Drop or clicking multiple elements With Control key) are done using the advanced user interactions API . It contains Actions and Action classes which are needed when performing these events. In order to perform action events, we need to use org.openqa.selenium.interactions.Actions class.

The build() method is used compile all the listed actions into a single step.
we have to use build() when we are performing sequence of operations and no need to use only if we are performing single action.

example where build() required
Actions builder = new Actions(driver);
builder.clickAndHold((WebElement)listItems.get(0)).clickAndHold((WebElement)listItems.get(3)).click().build().perform();


in the above code we are performing more than one operations so we have to use build() to compile all the actions into a single step

example where build is not required

WebElement draggable = driver.findElement(By.id("draggable")); 
WebElement droppable = driver.findElement(By.id("droppable")); 
new Actions(driver).dragAndDrop(draggable, droppable).perform();
in the above code we are performing just a single operations so no need to use build()

1 comment:

Blogger-story said...

https://blogger-story.com/best-free-blogging-sites/

Post a Comment

Which one is right ?

Translate







Tweet