我在Ubuntu Linux/Firefox 13和WATIR上。 (watir-webdriver-0.6.1) 我有一个网页,其中包含大约16个iframe的链接..所有这样链接.... 点击“11”将带来一个名称和id等于“page_11”当从iframe切回时,WATIR无法在父级上找到链接或按钮
<a href="javascript:nextPage(8);">9</a>
<a href="javascript:nextPage(9);">10</a>
<a href="javascript:nextPage(10);">11</a>
<a href="javascript:nextPage(11);">12</a>
单击该数字将使IFRAME进入页面,页面上是注释的另一盒(主页)
这是我** ** DO知道,因为我已经验证它由剧本。该页面将显示全部16个链接。我有我的WATIR脚本来点击第11个链接。它是这样做的,它会填充文本框,然后通过使用browser.frame(:index,0).locate方法返回主页面,并填写驻留在iframes所在位置下方的注释框填入。
这都不是问题。
问题是试图获取脚本,然后单击标有“12”的链接。 (它需要依次经过这些内联框)
它无法再在主页上找到链接(或针对该问题的按钮)。我结束了....
[remote server] file:///tmp/webdriver-profile20120730-32067-1haylz3/extensions/[email protected]/components/command_processor.js:5780:in `unknown': Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError)
我的脚本(相关部分)低于....
#!/usr/local/bin/ruby
require 'rubygems'
require 'watir-webdriver'
require "webdriver-user-agent"
require 'headless'
require 'thread'
#Firefox 13 path below. Doesn't work with 14
Selenium::WebDriver::Firefox.path = '/home/janie/Downloads/firefox/firefox'
profile = Selenium::WebDriver::Firefox::Profile.new
profile.native_events = false;
browser=Watir::Browser.new :firefox, :profile => profile
browser.goto("http://myurl/test")
browser.link(:text,"11").click
browser.frame(:name,"page_11").locate
puts "Text fields "
puts browser.frame(:name,"page_11").text_fields.length
$counter=0
#This if loop works like a champ
if browser.frame(:id,"page_11").text_fields.length > 0
puts "Found and iterating through Text Boxes"
while $counter < browser.frame(:id, "page_11").text_fields.length do
browser.frame(:id, "page_11").text_field(:index, $counter).set("Robot_Test")
end
end
#Now go back to the main page
browser.frame(:index,0).locate
#The below works too so I know I am back on the top level/parent
if browser.text.include? "This is the main page"
puts "--> Test Passed. Found the test string"
else
puts "--> Test Failed! Could not find:"
end
#Now we are back in the main page again
browser.text_field(:name,"COMMENTS").set("ROBOT_TEST")
#The above works great
#And now the problem.....
browser.link(:text,"12").click
KABOOM!上面找不到元素错误。
出于某种原因,它不再看到主页或按钮上的链接。任何想法可能会造成这种情况?我一直在寻找这一整天,而这个关于在我能运行这个脚本之前剩下的唯一的东西,其他的一切都很好。
有谁知道如何解决这个行为在Watir? 非常感谢! 珍妮
PS - 我在Chrome尝试测试,我得到..
/usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok': Element must be displayed to click (Selenium::WebDriver::Error::ElementNotVisibleError)
只是想我要补充。
HTML非常庞大,所以我尽量简洁。
注意,更多的故障诊断: .....显然这个问题似乎是脚本只是没有成功地进行跳转回父帧索引:0
脚本修改...在页
puts "Javascript links in page"
puts browser.links(:text, /^\d+$/).length
Javascript链接
(正确)指数
puts "Link attribute of index:3"
puts browser.link(:index,3).text
链接属性:3
(正确)
browser.link(:text,"2").click
(是的,正常工作)
#Refocus just to be safe
browser.frame(:index,0).locate
(上面一行是毫无意义的。聚焦和调整回框架:指数:0没有区别)
Javascript链接在页面
#We're supposed to be back in parent. Let's check the no. of links again
puts "Javascript links in page - after"
puts browser.links(:text, /^\d+$/).length
- 后
(这让我觉得一切都很好)
puts "Link attribute of index:3"
puts browser.link(:index,3).text
应返回“2”如上述,但没有值和下面的错误消息.....
/usr/local/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.5.8/lib/watir-webdriver/elements/element.rb:365:in `assert_exists': unable to locate element, using {:text=>"3", :tag_name=>"a"} (Watir::Exception::UnknownObjectException)
from /usr/local/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.5.8/lib/watir-webdriver/elements/element.rb:95:in `click'
注2:更基本:
puts "Clicking link 2"
browser.link(:text,"2").click
没问题
puts "Clicking link 3"
browser.link(:text,"3").click
错误
/usr/local/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.21.2/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok': Element must be displayed to click (Selenium::WebDriver::Error::ElementNotVisibleError)
我无法复制这个。我们可以得到一些(基本)HTML有这个问题? – anonygoose 2012-07-31 10:58:39
我确定这可能是简单的,但我将不得不使用Perl的WWW :: Mechanize,直到我能够找出问题所在。如果我想出了一个解决方案,我会重新发布。 – 2012-07-31 13:16:03
页面链接在页面的主要部分还是在另一个框架中?从你的代码看,你的'主页'是第一个框架。 – 2012-07-31 15:22:49