Похоже, может быть ошибка с вашими выражениями Xpath. Мне кажется, что они ожидают элемент с идентификатором «1», «2» или «3» в верхней части иерархии, содержащей два div, затем таблицу и т. Д. Я думаю, что есть более простой способ построить как Xpath, так и Ruby-код.
Xpath
First, you'll want to get a single Xpath that's robust enough to select multiple table rows. I'm not sure if it's necessary to select the <tr>
both by numerical position and by ID, but you can make this work either way. I don't know what kind of range you want, but you can modify either of these two Xpaths to get the range you want:
Select by ID
//div/div/table/tbody/tr[@id>0 and @id<4]
Select by Position
//div/div/table/tbody/tr[position()>0 and position()<4]
Ruby Code
The next thing you'll need to do is create an array with all of the elements you want. The same way you can declare a value to act as a browser element in Selenium, you can declare an array to contain multiple values each corresponding to a browser element. That is:
foo = $driver.find_element(:Xpath, "//div/div/table/tbody/tr[1]/td[2]")
foo.text
would be the same as using just one element of an array, bar:
bar[0] = $driver.find_element(:Xpath, "//div/div/table/tbody/tr[1]/td[2]")
bar[0].text
Both of these would return "NA" using your sample page above.
Now you just need to grab all the elements together, and then click on each one in turn with an "each" iterator. You can use .find_elements for this - it works just the same as .find_element, but returns all possible matches from the page as an array. Like this:
foo = $driver.find_elements(:Xpath, "//div/div/table/tbody/tr[@id>0 and @id<4]")
foo.each do |element|
element.click
end
Hope this helps!