<iframe name:something1>
<form id:something2>
<ul>
<li>
<input class = "class a" id = "id1" name = "name1">
</li>
<li>
<input class = "class b" id = "id2" name = "name2">
</li>
<li>
<input class = "class c" id = "id3" name = "name3">
</li>
<li>
<input id = "sbmt_btn" type = "submit">
</li>
</ul>
</form>
</iframe>
require "watir-webdriver"
b = Watir::Browser.new :chrome
b.goto "mysite.com"
b.frame(:name, "something1").text_field(:id, "id1").set "45" #line1
b.frame(:name, "something1").text_field(:id, "id2").set "Hello" #line2
b.frame(:name, "something1").text_field(:id, "id3").set "World" #line3
b.frame(:name, "something1").button(:id, "sbmt_btn").click #line4
问题:第1行和第2行成功运行。但是系统在执行第3行时会抛出错误。系统找不到id = id3和id = sbmt_btn的对象。我经历了很多页面来解决这个问题,但却无法解决。请帮忙。 我的红宝石版本:ruby 1.9.3p362
提前致谢。
答案 0 :(得分:0)
尝试使用when_present命令:
. . .
b.frame(:name, "something1").text_field(:id, "id3").when_present.set "World"
. . .