如何返回 Ruby 中的当前帧?

How can I back to current frame in Ruby?

我正在使用 Capybara 和 Ruby 开发自动化测试。我切换框架以访问报告页面中的某些 WebElement,然后我需要返回到当前框架,但它没有 ID。 我该怎么做?

这是我切换框架访问报告页面时的代码:

def check_report(report)
  frame = @session.find("//*[@id=\"OF_jreport\"]")
  @session.switch_to_frame(frame)
end

比我试过的:

 @session.switch_to.default_content()

我收到一条消息,询问我的意思是不是 switch_to_frame,但它也不起作用。

在我的 HTML 代码中没有另一个 Iframe ID,我的 WebElement xpath 是 /html/body/div[11]/div[1]/div[2]/a

水豚: 我建议使用 within_frame,这样一旦框架中的操作完成,句柄就会退回。

def check_report(report)
  frame = @session.find("//*[@id=\"OF_jreport\"]")
  within_frame(frame) do
    # write your logic to perform operations in the frame
  end
end

或者您可以尝试以下方法切换到默认框架。

@session.switch_to_frame(:top)

Ruby: 请使用以下切换到默认内容。

 @session.switch_to_default_content

如果你想切换到父框架然后使用下面

@session.switch_to_parent_frame