在站点上,有一个节点树,每个节点都与一个复选框相关联。然后这些节点进一步扩展为更多复选框。它看起来类似于下面的 where[]
代表一个复选框:
+ [] All
+ [] Fruit
+ [] Vegetables
然后展开看起来像这样:
+ [] All
- [] Fruit
[] apple
- [] Vegetables
[] potato
[] cucumber
然后在屏幕底部有一个按钮,当按下该按钮时,将为您提供所选商品的价格。
我想在 Watir 中编写一个执行以下事件序列的脚本:
1) Expands the node Fruit
2) Checks apple
3) Clicks the run button
4) Unchecks apple
5) Expands the node Vegetables
6) Checks potato
7) Clicks the run button
8) Unchecks potato
etc.. for all checkboxes and nodes
苹果复选框的标签如下所示:
<td onmouseover="TreeView_HoverNode(ContentPlaceHolder1_tvPartners_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;" class="">
<input type="checkbox" name="ContentPlaceHolder1_tvPartnersn2CheckBox" id="ContentPlaceHolder1_tvPartnersn2CheckBox">
<a class="ContentPlaceHolder1_tvPartners_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$tvPartners','s0\\0\\189')" onclick="TreeView_SelectNode(ContentPlaceHolder1_tvPartners_Data, this,'ContentPlaceHolder1_tvPartnerst2');" id="ContentPlaceHolder1_tvPartnerst2">
<font style="color:#FF0000;">apple</font>
</td>
此外,还有更多节点和项目稍后将添加到列表中,因此我需要脚本将其考虑在内并按顺序遍历复选框,而不调用复选框的特定 ID。
解决此问题的任何帮助将不胜感激。非常感谢!
更新:我想出了这段代码,但我想检查最后一个复选框/节点,而不是硬编码 for 循环。我还想跳过水果和蔬菜等节点的复选框。
for n in (1...250)
nodename = "ContentPlaceHolder1_tvPartnersn" + n.to_s
if ie.a(:id => nodename).exists?
ie.link(:id, nodename).click
end
end
ie.checkbox(:id => "ContentPlaceHolder1_tvPartnersn0CheckBox").clear
x = 1
for r in (1...250)
checkboxname = "ContentPlaceHolder1_tvPartnersn" + x.to_s + "CheckBox"
nodename = "ContentPlaceHolder1_tvPartnersn" + r.to_s
if ie.a(:id => nodename).exists?
x = x+1
checkboxname = "ContentPlaceHolder1_tvPartnersn" + x.to_s + "CheckBox"
end
if ie.checkbox(:id => checkboxname).exists?
ie.checkbox(:id => checkboxname).set
puts x
ie.checkbox(:id => checkboxname).clear
end
x = x + 1
end
更新:这里有更多的 HTML。我实际上有一个哈希设置为 itemlist[[n,"item"]]=item,例如 itemlist[[1,"item"]] = apple,它包含我需要检查价格的所有项目。有没有办法/是否更容易查看每个复选框的文本是什么,然后如果 itemlist.has_value?(checkbox_text) 然后选中该框并将该文本分配给另一个哈希?基本上,有没有办法根据文本而不是复选框的ID来检查框?
<td><a id="ContentPlaceHolder1_tvPartnersn0" href="javascript:TreeView_ToggleNode(ContentPlaceHolder1_tvPartners_Data,0,document.getElementById('ContentPlaceHolder1_tvPartnersn0'),'-',document.getElementById('ContentPlaceHolder1_tvPartnersn0Nodes'))"><img src="/WebResource.axd?d=VNrMPzAA2o87avzl3UgiY8OisS6wrOp46COe6QqNhDQHCsy9zX-GTuzHAKk7njulOEns3hNoLIxbv9x1bv530iY_Shsd9ZHlF3pm4jNQi6u0zB6atkT0-K9kirzHDQNHYxlY8Q2&t=634963835619397560" alt="Collapse All (133,060)" style="border-width:0;" /></a></td><td onmouseover="TreeView_HoverNode(ContentPlaceHolder1_tvPartners_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;"><input type="checkbox" name="ContentPlaceHolder1_tvPartnersn0CheckBox" id="ContentPlaceHolder1_tvPartnersn0CheckBox" /><a class="ContentPlaceHolder1_tvPartners_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$tvPartners','s0')" onclick="TreeView_SelectNode(ContentPlaceHolder1_tvPartners_Data, this,'ContentPlaceHolder1_tvPartnerst0');" id="ContentPlaceHolder1_tvPartnerst0">All (133,060)</a></td>
</tr>
</table><div id="ContentPlaceHolder1_tvPartnersn0Nodes" style="display:block;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><a id="ContentPlaceHolder1_tvPartnersn1" href="javascript:TreeView_ToggleNode(ContentPlaceHolder1_tvPartners_Data,1,document.getElementById('ContentPlaceHolder1_tvPartnersn1'),'t',document.getElementById('ContentPlaceHolder1_tvPartnersn1Nodes'))"><img src="/WebResource.axd?d=D2aGfOHUjBmg4quHNr-mKkyc5juoGHdurzZqtoCU3qo2d457eKX9x0d2AS3LrrQULzPjC-9wC6hLlMxSFEvU6c9r8LmzgOeKWAi6ouEEkShvclKr0&t=634963835619397560" alt="Expand Ace Communications Group (0) <img src='images/emergency.png' alt='alert' />" style="border-width:0;" /></a></td><td onmouseover="TreeView_HoverNode(ContentPlaceHolder1_tvPartners_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;"><input type="checkbox" name="ContentPlaceHolder1_tvPartnersn1CheckBox" id="ContentPlaceHolder1_tvPartnersn1CheckBox" /><a class="ContentPlaceHolder1_tvPartners_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$tvPartners','s0\\0')" onclick="TreeView_SelectNode(ContentPlaceHolder1_tvPartners_Data, this,'ContentPlaceHolder1_tvPartnerst1');" id="ContentPlaceHolder1_tvPartnerst1">Fruit </a></td>
</tr>
</table><div id="ContentPlaceHolder1_tvPartnersn1Nodes" style="display:none;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img src="/WebResource.axd?d=UZyrk961AUQRa1Dg14aXeNUU3AZcfF9PiakU0o_cO8MfbyWz58k50vr47p2ICDOjgAqF5UX_lVIhbj_y2BqKRU5Xwhic3cBNooK1CBd_cGP6COn60&t=634963835619397560" alt="" /></div></td><td><img src="/WebResource.axd?d=OftTkmJCEf6tGohvvdo_cbMxdnyHMLxScANk1YxbAhfKKp3_gvqoKFAIbK4gGFAKMagH78cKVSIS61WrK5fGcCaHWVUMPjXLTtDZIJISdqqtXFNI0&t=634963835619397560" alt="" /></td><td onmouseover="TreeView_HoverNode(ContentPlaceHolder1_tvPartners_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;"><input type="checkbox" name="ContentPlaceHolder1_tvPartnersn2CheckBox" id="ContentPlaceHolder1_tvPartnersn2CheckBox" /><a class="ContentPlaceHolder1_tvPartners_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$tvPartners','s0\\0\\189')" onclick="TreeView_SelectNode(ContentPlaceHolder1_tvPartners_Data, this,'ContentPlaceHolder1_tvPartnerst2');" id="ContentPlaceHolder1_tvPartnerst2"><font style='color:#FF0000;'>apple</font> </a></td>
</tr>
</table>
</div><table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><a id="ContentPlaceHolder1_tvPartnersn3" href="javascript:TreeView_ToggleNode(ContentPlaceHolder1_tvPartners_Data,3,document.getElementById('ContentPlaceHolder1_tvPartnersn3'),'t',document.getElementById('ContentPlaceHolder1_tvPartnersn3Nodes'))"><img src="/WebResource.axd?d=D2aGfOHUjBmg4quHNr-mKkyc5juoGHdurzZqtoCU3qo2d457eKX9x0d2AS3LrrQULzPjC-9wC6hLlMxSFEvU6c9r8LmzgOeKWAi6ouEEkShvclKr0&t=634963835619397560" alt="Expand Advantage (0)" style="border-width:0;" /></a></td><td onmouseover="TreeView_HoverNode(ContentPlaceHolder1_tvPartners_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;"><input type="checkbox" name="ContentPlaceHolder1_tvPartnersn3CheckBox" id="ContentPlaceHolder1_tvPartnersn3CheckBox" /><a class="ContentPlaceHolder1_tvPartners_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$tvPartners','s0\\0')" onclick="TreeView_SelectNode(ContentPlaceHolder1_tvPartners_Data, this,'ContentPlaceHolder1_tvPartnerst3');" id="ContentPlaceHolder1_tvPartnerst3">Vegetable</a></td>
</tr>
</table><div id="ContentPlaceHolder1_tvPartnersn3Nodes" style="display:none;">
<table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img src="/WebResource.axd?d=UZyrk961AUQRa1Dg14aXeNUU3AZcfF9PiakU0o_cO8MfbyWz58k50vr47p2ICDOjgAqF5UX_lVIhbj_y2BqKRU5Xwhic3cBNooK1CBd_cGP6COn60&t=634963835619397560" alt="" /></div></td><td><img src="/WebResource.axd?d=yCq0KCcfK0lqwrgCU1UxuFJ0bJHMKjxD6S5t8OvIWXwTUBOYh1ZiQA4lD3ZpRuMNI-itrPIn3_rFzvZtrMP5g7PyyensT-Z003WldrY9pIgMSY5p0&t=634963835619397560" alt="" /></td><td onmouseover="TreeView_HoverNode(ContentPlaceHolder1_tvPartners_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;"><input type="checkbox" name="ContentPlaceHolder1_tvPartnersn4CheckBox" id="ContentPlaceHolder1_tvPartnersn4CheckBox" /><a class="ContentPlaceHolder1_tvPartners_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$tvPartners','s0\\0\\119')" onclick="TreeView_SelectNode(ContentPlaceHolder1_tvPartners_Data, this,'ContentPlaceHolder1_tvPartnerst4');" id="ContentPlaceHolder1_tvPartnerst4">potato</a></td>
</tr>
</table><table cellpadding="0" cellspacing="0" style="border-width:0;">
<tr>
<td><div style="width:20px;height:1px"></div></td><td><div style="width:20px;height:1px"><img src="/WebResource.axd?d=UZyrk961AUQRa1Dg14aXeNUU3AZcfF9PiakU0o_cO8MfbyWz58k50vr47p2ICDOjgAqF5UX_lVIhbj_y2BqKRU5Xwhic3cBNooK1CBd_cGP6COn60&t=634963835619397560" alt="" /></div></td><td><img src="/WebResource.axd?d=yCq0KCcfK0lqwrgCU1UxuFJ0bJHMKjxD6S5t8OvIWXwTUBOYh1ZiQA4lD3ZpRuMNI-itrPIn3_rFzvZtrMP5g7PyyensT-Z003WldrY9pIgMSY5p0&t=634963835619397560" alt="" /></td><td onmouseover="TreeView_HoverNode(ContentPlaceHolder1_tvPartners_Data, this)" onmouseout="TreeView_UnhoverNode(this)" style="white-space:nowrap;"><input type="checkbox" name="ContentPlaceHolder1_tvPartnersn5CheckBox" id="ContentPlaceHolder1_tvPartnersn5CheckBox" /><a class="ContentPlaceHolder1_tvPartners_0" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$tvPartners','s0\\0\\1')" onclick="TreeView_SelectNode(ContentPlaceHolder1_tvPartners_Data, this,'ContentPlaceHolder1_tvPartnerst5');" id="ContentPlaceHolder1_tvPartnerst5">cucumber</a></td>
</tr>