c# - WebDriver Actions.Perform() 或 Actions.Build().Perform()

标签 c# selenium selenium-webdriver webdriver

我在 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/

相关文章:

html - 如何通过 XPath 检索 [object Text]?

selenium-webdriver - 如何使用 TestNg 和 eclipse 在多个浏览器中一个接一个地运行 Selenium webdriver 测试用例

C# 方法有 1 个参数,但使用 2 个参数调用

c# - 更新二进制文件信息

c# - 如何将头文件 (.h) 文件中的用户定义数据类型导入到 C#

selenium - 自定义 Selenium Hub 官方 docker 镜像返回 'Permission denied'

android - 在 Android 上运行 Selenium 测试

java - 如何验证 selenium Web 驱动程序中类属性中的图像

java - Webdriver : ExpectedConditions. invisibilityOf 不起作用。总是抛出异常

c# - 我可以通过 Lucene 在 Orchard 中搜索/索引自定义数据源吗?