Selenium webDriver操作,无需调用build()

时间:2019-05-18 00:57:11

标签: selenium webdriver

没有build()的动作:

Actions actions = new Actions(driver);
actions.doubleClick(element).perform();

这似乎很好用,而无需在perform()之前调用build()。有什么区别?

1 个答案:

答案 0 :(得分:0)

从Java绑定中的源代码中,build()perform()的定义很简单:

/**
   * Generates a composite action containing all actions so far, ready to be performed (and
   * resets the internal builder state, so subsequent calls to {@link #build()} will contain fresh
   * sequences).
   *
   * @return the composite action
   */
  public Action build() {
    Action toReturn = new BuiltAction(driver, new LinkedHashMap<>(sequences), action);
    action = new CompositeAction();
    sequences.clear();
    return toReturn;
  }

  /**
   * A convenience method for performing the actions without calling build() first.
   */
  public void perform() {
    build().perform();
  }

显然,只需执行简单的调用构建,因此使用perform()build().perform()之间没有功能上的区别