Dvc1201 Dvc1201 - 7 days ago 7
C# Question

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

Answer

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#355

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

Comments