WebDriver Actions.Perform()或Actions.Build().Perform()

Dvc*_*201 4 c# selenium webdriver selenium-webdriver

我在C#中使用Selenium2 WebDriver

Actions.Build - 返回IAction可用于执行操作的组合.(IActions有一个执行操作的Perform方法)Actions.Perform - 执行当前构建的操作.

在大多数考试中使用这样的动作:

new Actions(IWebDriverObj).actions...Build().Perform()
Run Code Online (Sandbox Code Playgroud)

但这也有效

new Actions(IWebDriverObj).actions...Perform()  //no Build before Perform
Run Code Online (Sandbox Code Playgroud)

是否有必要在Perform()或Build()之前使用Build()仅用于某些兼容性目的?

提前谢谢你的答案

Yi *_*eng 11

始终牢记Selenium是开源的.

源码WebDriver/Interactions/Actions.cs在这里,显然你可以看到Perform()包含Build(),所以答案是否定的,你不需要在执行之前构建,除非你想通过内置IAction而不执行.

/// <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();
}
Run Code Online (Sandbox Code Playgroud)

另外,对于阅读这篇文章的其他人:

Java绑定:build()包含在perform().来源: interaction/Actions.java

Ruby/Python:只有perform,没有这样的东西叫build.来源:action_chains.py,action_builder.rb