Thursday, October 23, 2025
HomeLanguagesSelenium – Search for text on page

Selenium – Search for text on page

Prerequisite:- Selenium

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 learn how to know whether the text is on a web page or not using selenium in python.

Approach:

  • First, we will open the chrome driver using the Chrome() method in the Selenium web driver
  • Assign the Web URL.
  • Then the driver will open the Given Web URL
  • Get Web Page Source Code using page_source property.
  • Assign the text to be searched.
  • After getting the web page text, we will search whether the text is present or not.

Below is the implementation:

Python3




# import webdriver
from selenium import webdriver
 
# create webdriver object
driver = webdriver.Chrome()
 
# URL of the website
 
# Opening the URL
driver.get(url)
 
# Getting current URL source code
get_source = driver.page_source
 
# Text you want to search
search_text = "Floor"
 
# print True if text is present else False
print(search_text in get_source)


Output:

True

Demonstration:

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS