I have a situation where I must click a span elements, which makes parts of the DOM vissible (that I must verify). A javascript click eventhandler makes the part of the DOM vissble. But when using capybaras click_on it seems that it only searches through a and button elements. So triggering this javascript click eventhandler seems impossible.
Have you tried using find, e.g.
find('#id_of_element').click
Thanks a lot. that was a way around it... I use
page.find(:xpath,"//*[text()='#{click_text}']").click
where click_text is the human readable text.
You should consider using normalize-space() rather than text() - this is what Capybara (XPath) uses internally for finding nodes by text - as the actual text of your html nodes often will contain trailing and following whitespace, and also multiple whitespace between words, which is normalized by the browser for display.
Thanks for the tip.
2013/11/28 Adrian Longley [email protected]
You should consider using normalize-space() rather than text() - this is
what Capybara (XPath) uses internally for finding nodes by text - as the
actual text of your html nodes often will contain trailing and following
whitespace, and also multiple whitespace between words, which is normalized
by the browser for display.—
Reply to this email directly or view it on GitHubhttps://github.com/jnicklas/capybara/issues/1200#issuecomment-29449125
.
page.find_all(:xpath, "//*[normalize-space(text())='#{link_text}']").first.click
Most helpful comment
Thanks a lot. that was a way around it... I use
where
click_textis the human readable text.