Ruby cucumber watir-webdriver不识别放置在框架中的对象

时间:2013-10-28 14:48:14

标签: ruby watir watir-webdriver

工作但添加条件链接的Watir代码在这里不再识别:(

require 'spec'
require 'watir'

browser = Watir::Browser.new 
pages = { "RCM Workspace Homepage" => "http://rcm-bpmt.apmoller.net/workspace/faces/jsf/workspace/workspace.xhtml" }

Given(/^that I am on the (.*?)$/) do |page|
  # Opening new browser and going to the page which is specified
  browser.goto(pages[page])

  #Maximizing the opened browser window
  browser.maximize
end

When(/^I search for (.*?)$/) do |text|
  # Ensuring that we have opened expected page only by verifying the page content 
  browser.html.include?(text).should == true 
end

Then(/^I click on Show Filters link$/) do
  #Opening the Conditions window by clicking on the show filters link 
  browser.link(:id, "portletComponentWorkList_viewNormalModeWorkList_viewPanel_showFiltersLink").click

  #Clicking on Add condition link which is placed in a frame and it opnes when I click on Show filters link
  browser.element(:id, 'portletComponentWorkList_viewNormalModeWorkList_viewPanel_conditionButton').click
end

HTML详细信息:

<A id=portletComponentWorkList_viewNormalModeWorkList_viewPanel_conditionButton onclick="oc.ajax.jsf.doCallback('portletComponentWorkList','portletComponentWorkList:viewNormalModeWorkList:viewPanel:conditionButton');return false;" href="http://rcm-bpmt.apmoller.net/workspace/faces/jsf/workspace/workspace.xhtml#">
  Add condition
</A>

1 个答案:

答案 0 :(得分:0)

在以下行中,Watir将在框架中的之外的任何位置查找元素。

browser.element(:id, 'portletComponentWorkList_viewNormalModeWorkList_viewPanel_conditionButton').click

与其他元素不同,您必须告诉Watir何时元素在框架中。这与您将元素搜索范围扩展到特定元素的方式类似。

例如,如果只有一帧或你的元素在第一帧中,你可以这样做(注意添加.frame):

browser.frame.element(:id, 'portletComponentWorkList_viewNormalModeWorkList_viewPanel_conditionButton').click

如果有多个帧,则需要添加参数以更具体地说明要使用的帧。例如,如果框架具有id:

browser.frame(:id => 'myframe').element(:id, 'portletComponentWorkList_viewNormalModeWorkList_viewPanel_conditionButton').click