2016-10-02 124 views
0

Git this page https://ru.aliexpress.com/store/product/Original-xiaomi-Redmi-note3-snapdragon-650-4000mAh-13ML-1080P-3G-32G-5-5-screen-octa-core/1986585_32622877163.html?detailNewVersion=&categoryId=5090301 我需要点击每个颜色修改,因为我认为。所有配置和驱动程序工作正常cuz`页上我可以互动的其他元素。点击img水豚

代码

page.all(:css, '.item-sku-image img').each_with_index do |mod,i| 

     find(:xpath,"//img[@title='#{mod['title']}']").find(:xpath, "..").click 

     puts find(:xpath,"//img[@title='#{mod['title']}']").find(:xpath, "..").find(:xpath, "..")['class'] # with this line i'm checkin` if i clicked on img block cuz his parend node changes it's class to active 
    end 

不知道我为什么可以点击每一个项目或链接此页面上,除了IMG的此块。 (使用poltergeist)

回答

0

没有必要重复元素,事实上它应该是完全正确的单击img元素本身。

page.all(:css, '.item-sku-image img').each_with_index do |mod,i| 
    mod.click # mod.find(:xpath, "./..").click if you do need to click the parent 
    puts mod.find(:xpath, "./ancestor::li").matches_selector?(:css, '.active') 
end