如何使用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/?&$b=BLM/swatches/&layer=0&size=46,23&src=is{$b$9/optimized/8201409_fpx.tif}&cropN=0,0,2,1&anchor=0,0&layer=1&size=23,23&src=is{$b$0/optimized/8189800_fpx.tif}&anchor=0,0&posN=0.5,0&layer=2&op_sharpen=1&fmt=jpeg&qlt=90,0&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/?&$b=BLM/swatches/&layer=0&size=46,23&src=is{$b$9/optimized/8201409_fpx.tif}&cropN=0,0,2,1&anchor=0,0&layer=1&size=23,23&src=is{$b$0/optimized/8189800_fpx.tif}&anchor=0,0&posN=0.5,0&layer=2&op_sharpen=1&fmt=jpeg&qlt=90,0&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似乎无法点击“隐藏”输入。
由于
答案 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