使用ruby webdriver单击/选择隐藏属性

时间:2014-01-12 04:21:17

标签: ruby selenium

如何使用ruby命令点击“Black”li元素的隐藏输入(或将其设置为“selected”)?

 <li title="Bright Rose" class="memberHidden selected">
    <img id="swatch901489#1_0" class="colorSwatch" style="background:url('http://someimages.com/is/image/BLM/?&amp;$b=BLM/swatches/&amp;layer=0&amp;size=46,23&amp;src=is{$b$9/optimized/8201409_fpx.tif}&amp;cropN=0,0,2,1&amp;anchor=0,0&amp;layer=1&amp;size=23,23&amp;src=is{$b$0/optimized/8189800_fpx.tif}&amp;anchor=0,0&amp;posN=0.5,0&amp;layer=2&amp;op_sharpen=1&amp;fmt=jpeg&amp;qlt=90,0&amp;hei=23') 46px 0 transparent;" title="Bright Rose" alt="Bright Rose">
    <input type="hidden" id="swatch901489#1_0_imgurl" value="9/optimized/8201409_fpx.tif">
 </li>

 <li title="Black" class="memberHidden ">
    <img id="swatch901489#2_0" class="colorSwatch" style="background:url('http://someimages.com/is/image/BLM/?&amp;$b=BLM/swatches/&amp;layer=0&amp;size=46,23&amp;src=is{$b$9/optimized/8201409_fpx.tif}&amp;cropN=0,0,2,1&amp;anchor=0,0&amp;layer=1&amp;size=23,23&amp;src=is{$b$0/optimized/8189800_fpx.tif}&amp;anchor=0,0&amp;posN=0.5,0&amp;layer=2&amp;op_sharpen=1&amp;fmt=jpeg&amp;qlt=90,0&amp;hei=23') 23px 0 transparent;" title="Black" alt="Black">
    <input type="hidden" id="swatch901489#2_0_imgurl" value="0/optimized/8189800_fpx.tif">
  </li>

该元素位于我正在抓取的第三方网站上。由于某些原因,chrome和firefox webdrivers似乎无法点击“隐藏”输入。

由于

1 个答案:

答案 0 :(得分:0)

您可以使用execute_script执行此操作:

script = <<-ejs
var y = document.getElementById('swatch901489#2_0_imgurl');
y.type= 'button';
return y;
ejs

driver.execute_script(script).click