css - Finding specific div element just below span with title text in cucumber -


i using cucumber , capybara test web page following outline.

<span> title 1 </span> <span> text </span> <div> link y </div> <span> title 2 </span> <span> text </span> <div> link y </div> <span> title 3 </span> <span> text </span> <div> link y </div> 

i want click on link below title 2. since links have same name , same css except being asynchronous ajax calls, can use in finder somehow? want design helper method takes title , finds link exact xpath not work.

what have tried far:

within(find("span", :text => title))   within(find(:xpath, "../div"))     click_link 'publish'   end end 

as can tell xpaths not strong point.

i've tried going through native getting path of capybara:node:element using: find("span", :text => title).path hoping extract child nbr of title span using div such find(:xpath, "/div[n]"). .path gives me error telling me not supported webdriver, using selenium webdriver since page contains asynchronous ajax calls.

i've tried looking @ .native selenium webdriver element not found in there.

please help! before tell me to, no can not change webpage in way.

you want do:

title = "title 2" within( find(:xpath, "//span[normalize-space(text())='#{title}']/following-sibling::div[1]") )     click_link 'publish' end 

an explanation of xpath:

  1. //span[normalize-space(text())='#{title}'] looks span title. note normalize-space(text()) used make handling of spaces easier removing spaces. allows specifying title "title 2" instead of having " title 2 " (ie having specify leading/trailing space).
  2. /following-sibling::div[1] says span found, find first div element follows.

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -