我在 C# 中使用 Selenium2 WebDriver
Actions.Build - 返回可用于执行操作的复合 IAction
。 (IActions 有一个 Perform 方法来执行 Action )
Actions.Perform - 执行当前构建的操作。
在大多数考试中使用这样的 Action :
new Actions(IWebDriverObj).actions...Build().Perform()
但这也行
new Actions(IWebDriverObj).actions...Perform() //no Build before Perform
是否有必要在 Perform() 之前使用 Build() 或 Build() 仅出于某些兼容性目的?
预先感谢您的回答
最佳答案
请始终记住,Selenium 是开源的。
WebDriver/Interactions/Actions.cs
的来源是here ,很明显可以看到Perform()
包含了Build()
,所以答案是否定的,你不需要先build再执行,除非你想通过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();
}
此外,对于阅读这篇文章的其他人:
Java 绑定(bind):build()
包含在 perform()
中。来源:interactions/Actions.java
Ruby/Python:只有perform
,没有build
。来源:action_chains.py , action_builder.rb
关于c# - WebDriver Actions.Perform() 或 Actions.Build().Perform(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16435798/