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
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.
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.
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.
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.
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
Actually, the .perform()
includes a .build()
.
So you can only write : new Actions(IWebDriverObj).actions....perform()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With