There's a html code
<p>
test text
<br/>
test2
<p/>
When performing the method:
.find(:xpath, "/html/p").text
result:
test text test2
How can I get the "two lines"
test text
test2
Capybara tries to follow the webdriver spec when it makes sense, which means #text
returns normalized text content with carriage returns/linefeeds removed and therefore doesn't fulfill your needs.
Unfortunately capybara-webkit doesn't return element properties when accessed through #[]
so this won't work with capybara-webkit - it should work with selenium or poltergeist though
However, since you're using one of the real browser drivers (not rack-test) you should be able to access the elements innerText property by doing
find(:xpath, "/html/p")['innerText']
which should provide the output you're looking for
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.