Get all text of the page using Selenium in Python
Last Updated :
26 Oct, 2022
As we know Selenium is an automation tool through which we can automate browsers by writing some lines of code. It is compatible with all browsers, Operating systems, and also its program can be written in any programming language such as Python, Java, and many more.
Selenium provides a convenient API to access Selenium WebDrivers like Firefox, IE, Chrome, Remote, etc. The currently supported Python versions are 3.5 and above.
Installation:
Use pip to install the Selenium package. Just write this below command on Command Prompt.
pip install selenium
Once installation gets done. Open Python Console and just write these two commands for verifying whether Selenium is installed or not.
Python3
import selenium
print(selenium.__version__)
Output:
'3.141.0'
Webdriver Manager for Python:
Previously, We should download binary chromedriver and Unzip it somewhere on our PC and also set a path. After that, set path to this driver like this:
webdriver.Chrome(executable_path="D:\PyCharm_Projects\SeleniumLearning\Drivers\ChromeDriverServer.exe")
But Every time, a new version of the driver is released, so we need to download a new driver otherwise it will give us errors. For Solving this issue, we need to install webdriver-manager:
Installation:
pip install webdriver-manager
If we are using chrome driver, then we need to write these lines:
Python3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
Like Chrome, We have some other browsers also. For Example:
Use with Chromium:
Python3
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType
driver = webdriver.Chrome(ChromeDriverManager(chrome_type = ChromeType.CHROMIUM).install())
Use with FireFox:
Python3
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path = GeckoDriverManager().install())
Use with IE:
Python3
from selenium import webdriver
from webdriver_manager.microsoft import IEDriverManager
driver = webdriver.Ie(IEDriverManager().install())
Use with Edge:
Python3
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(EdgeChromiumDriverManager().install())
Get all text of the page using Selenium in Python
Let's learn how to automate the tasks with the help of selenium in Python Programming. Here in this article, We are discussing how to get all text of the page using selenium.
Approach:
- Import the webdriver from selenium module
- Here, in this article, we will automate the task on Chrome browser. So, We have to import ChromeDriverManager from the webdriver_manager.chrome. Now, We are not required to download any drivers from the internet. This command will automatically download the drivers from the Internet. Currently, Supported WebDriver implementations are Firefox, Chrome, IE, and Remote.
- Installing the Chrome driver and store in the instance of webdriver.
- The driver.get method will navigate to a page given by the URL. WebDriver will wait until the page gets fully loaded before returning control to our program.
- WebDriver gives various ways to find the elements in our page using one of the find_element_by_* methods. For example, Body section of the given page can be located with the help of it's xpath, we will use the  find_element_by_xpath method.
- Finally, for closing the browser window. We will use the driver.close method. One more method, we have driver.exit method which closes entire browsers where driver.close will close only one window tab.
Below is the Implementation:
Python3
# Importing necessary modules
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
# WebDriver Chrome
driver = webdriver.Chrome()
# Target URL
driver.get("https://www.geeksforgeeks.org/competitive-programming-a-complete-guide/")
# To load entire webpage
time.sleep(5)
# Printing the whole body text
print(driver.find_element(By.XPATH, "/html/body").text)
# Closing the driver
driver.close()
Output:

Similar Reads
How to get text of a tag in selenium - Python? Selenium is a powerful tool for controlling web browsers through programs and performing browser automation. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. In this article, we will w
1 min read
How to Locate Elements using Selenium Python? Selenium: is an open-source tool that automates web browsers. It provides a single interface that lets you write test scripts in programming languages like Ruby, Java, NodeJS, PHP, Perl, Python, and C#, among others. I personally prefer Python as itâs very easy to write code in python. A browser-dri
3 min read
Locating single elements in Selenium Python Locators Strategies in Selenium Python are methods that are used to locate elements from the page and perform an operation on the same. Seleniumâs Python Module is built to perform automated testing with Python. Selenium Python bindings provide a simple API to write functional/acceptance tests using
5 min read
Navigating links using get method - Selenium Python Selenium's Python module allows you to automate web testing using Python. The Selenium Python bindings provide a straightforward API to write functional and acceptance tests with Selenium WebDriver. Through this API, you can easily access all WebDriver features in a user-friendly way. This article e
2 min read
How to get current_url using Selenium in Python? While doing work with selenium many URL get opened and redirected in order to keeping track of URL current_url method is used. The current_url method is used to retrieve the URL of the webpage the user is currently accessing. It gives the URL of the current webpage loaded by the driver in selenium.
2 min read