2016-10-02 56 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