需求:

要把一个页面的所有删除超连接都点击一遍,且事先不知道会有多少删除的连接

 

代码:

require 'watir'    

@ie = Watir::IE.new
@ie.goto(url)
count = 0
@ie.links.each do |l| 
if l.name=~/delete/
  count = count + 1
  end
  end
  
for i in 0..count-1
if @ie.link(:name,'delete').exist?
  puts "exist"
@ie.link(:name,'delete').click
@ie.link(:id,"productdelete").click
end
end
@ie.close
 
注:如果需要用到class属性,则应该是l.class_name

相关文章:

  • 2021-10-19
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-02
  • 2021-12-01
  • 2022-12-23
  • 2021-11-21
  • 2021-07-03
  • 2021-12-08
  • 2022-12-23
相关资源
相似解决方案