Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebDriver Actions.Perform() or Actions.Build().Perform()

I use Selenium2 WebDriver with C#

Actions.Build - returns a composite IAction which can be used to perform the actions. (IActions has a Perform method to execute the actions) Actions.Perform - Performs the currently built action.

In most of the examles use Actions like this:

new Actions(IWebDriverObj).actions...Build().Perform()

but this works as well

new Actions(IWebDriverObj).actions...Perform()  //no Build before Perform

Is it necessary to use the Build() before the Perform() or Build() is for some compatibility purpose only?

Thanks in advance for the answers

like image 946
Dvc1201 Avatar asked May 08 '13 08:05

Dvc1201


People also ask

What is the use of build () and perform () in actions?

The build() method generates a composite action containing all actions which are ready to be performed. The perform() method is used to perform the series of actions that are defined.

What is build () perform () in selenium?

build() method in Actions class is use to create chain of action or operation you want to perform. perform() this method in Actions Class is use to execute chain of action which are build using Action build method. build().perform() = create chain of actions + execute.

What is the difference between build and perform method in selenium?

Difference between build() and perform() in SeleniumThe build() command of action interface generates a composite action that contains all the actions gathered which are ready to be performed. The perform() command is used to perform a sequence of actions without calling build() first.

What is action and actions in selenium WebDriver?

Actions class is an ability provided by Selenium for handling keyboard and mouse events. In Selenium WebDriver, handling these events includes operations such as drag and drop, clicking on multiple elements with the control key, among others. These operations are performed using the advanced user interactions API.


2 Answers

Always keep in mind that Selenium is open source.

The source of WebDriver/Interactions/Actions.cs is here, clearly you can see Perform() includes Build(), so the answer is no, you don't need to build before perform, unless you want to pass the built IAction around without performing.

/// <summary>
/// Builds the sequence of actions.
/// </summary>
/// <returns>A composite <see cref="IAction"/> which can be used to perform the actions.</returns>
public IAction Build()
{
    CompositeAction toReturn = this.action;
    this.action = new CompositeAction();
    return toReturn;
}

/// <summary>
/// Performs the currently built action.
/// </summary>
public void Perform()
{
    this.Build().Perform();
}

Also, for anyone else reading this post:

Java binding: build() is included in perform(). Source: interactions/Actions.java

Ruby/Python: only have perform, no such thing called build. Source: action_chains.py, action_builder.rb

like image 144
Yi Zeng Avatar answered Sep 19 '22 23:09

Yi Zeng


Actually, the .perform() includes a .build().

So you can only write : new Actions(IWebDriverObj).actions....perform()

like image 28
e1che Avatar answered Sep 21 '22 23:09

e1che