13

Can anybody tell me the difference between build.perform() and perform() in Selenium actions?

Example:

actions.moveToElement(menuHoverLink).perform(); 

and

actions.moveToElement(menuHoverLink).build().perform();

2 Answers 2

27

In your scenario it wont make a difference using both. The difference occurs at place when you have multiple actions to be performed like:

Actions builder = new Actions(driver); 
builder.clickAndHold(element1)
.clickAndHold(element2)
.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. Thus build() method is used compile all the listed actions into a single step. We use build() when we are performing sequence of operations and no need to use if we are performing single action.

2
  • Happy to help buddy... :) Mar 16, 2015 at 7:20
  • Hey @Vivek Singh I have a question when we can build and perform with the Actions class itself then what is the need of Action interface.For example: Actions a =new Actions(driver); Action b = a.doubleClick(element).build(); b.perform(); we can execute the same using a.doubleClick(element).build().perform();
    – shaik
    Oct 31, 2017 at 12:53
5

A bit late to the party, but you don't have to use build() unless you want to pass an IActions object, as build() is done by perform() (see WebDriver Actions.Perform() or Actions.Build().Perform())

Not the answer you're looking for? Browse other questions tagged or ask your own question.