Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get contents of entire page using Selenium [duplicate]

Tags:

Using Selenium for browser automation (Python).

If I understand correctly, the following code would be used

inputElement = driver.find_element_by_name("q") the_text = inputElement.text 

How would I go about getting the text on the whole page as opposed to looking within a particular element?

like image 390
Chris Dutrow Avatar asked Apr 19 '13 22:04

Chris Dutrow


People also ask

How do I getText to full page in Selenium?

New Selenium IDE There are more than one ways of achieving it. To get the text of the visible on the page we can use the method findElement(By. tagname()) method to get hold of . Next can then use the getText() method to extract text from the body tag.

What is the purpose of getText () and getAttribute ()?

The getText() method simply returns the visible text present between the start and end tags (which is not hidden by CSS). The getAttribute() method on the other hand identifies and fetches the key-value pairs of attributes within the HTML tags.

How do you extract text from a Web page using Selenium and save it as a text file?

We can extract text from a webpage using Selenium webdriver and save it as a text file using the getText method. It can extract the text for an element which is displayed (and not hidden by CSS).


1 Answers

Looks like the entire page text can be found in:

driver.page_source 
like image 172
Chris Dutrow Avatar answered Oct 03 '22 22:10

Chris Dutrow