Reputation: 107
I'm using Robotframework to automate tests, it uses the Selenium2 Library and gives the opportunity to extend many libraries (Java, Python, AngularJS, etc.).
Here's my question.
Is there a way to get all the texts displayed on a page?
I can get any specific text by the element locator, but currently I need to write a function which gets all the texts displayed on the page.
Does anyone know a way? Or a hint how to get things going?
Upvotes: 1
Views: 2739
Reputation: 20067
You can do that by getting the text content of the <body>
tag:
${text}= Get Text //body
Log ${text} # a very long string, with newlines as delimiters b/n the different tags
${text as list}= Split To Lines ${text}
Log ${text as list} # a list, each member is the different tag's text
Another (non-working with SE) way to do it is to go after each element, with a locator like //body//*
, producing webelements with Get Webelements
on it.
But when you callGet Text
on each produced webelement, it will return its text, plus the ones for all its children - thus duplicating the data. That can be done in pure xpath/xslt (with text()
, .
and normalize-space()
), but regretfully not through webdriver/selenium (it always expects a node as argument).
The purpose of that ^ de-tour from the answer was to present the outcome of a 2 minute research :), and to get any feedback from someone that might have actually accomplished it with Get Text
on each element of the page.
Upvotes: 1