开发者

Iterating through website links and clicking them

开发者 https://www.devze.com 2023-04-02 23:11 出处:网络
@editLinks = $ie.link(:text => \"Edit\", :class =>\"edit\" ).links @editLinks.each do|l| l.click
@editLinks = $ie.link(:text => "Edit", :class =>"edit" ).links
@editLinks.each do  |l| l.click 
end

I have the above code which iterates through a set of links which are called "Edit". When edit is clicked on the webpage, the text boxes become enabled and the user is able to type into them. There are different edit links for different textboxes. However, for some reason, the code is not iterating or giving me any errors. It just finishes the script without clicking any edit links. I've omitted the javascript onlcick stuff to show just the html. All the edit links on the webpage also have different ID's.

<a id="EditLinkButton" class="edit"><strong>Edit</strong开发者_如何学运维></a>


After reading Get Elements By Attributes question, I'd suggest doing something like the following:

@editLinks = $ie.links
@editLinks.each do |link|
  if link.attribute_value("class") == "edit" and link.text == "Edit"
    link.click
  end
end

There's probably a better way of doing this, but it works.

Edit:

After reading your comment below, perhaps something along the lines of this would be better

@edit_ids = %w(your edit link ids seperated by whitespace)
@edit_ids.each do |edit_id|
  $ie.link(:id => edit_id).click
  # whatever else you're doing
end

So that way you're looking them up in the DOM as and when you need them, rather than storing them and then their references becoming obsolete as the page changes during the test. Worth a shot.

0

精彩评论

暂无评论...
验证码 换一张
取 消