Open In App

Selenium – Search for text on page

Last Updated : 30 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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:


Previous Article
Next Article

Similar Reads

Get all text of the page using Selenium in Python
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,
3 min read
Close specific Web page using Selenium in Python
Prerequisites: Selenium Basics, Selenium close() and quit() 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. The close() meth
2 min read
Scroll Web Page Base On Pixel Method Using Selenium in 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. A Scrollbar is helped you to circulate round display in vertical route if th
2 min read
Get contents of entire page using Selenium
In this article, we will discuss ways to get the contents of the entire page using Selenium. There can broadly be two methods for the same. Let's discuss them in detail. Method 1: For extracting the visible text from the entire page, we can use the find_element_by_* methods which help us find or locate the elements on the page. Then, We will use th
2 min read
Python | Automate Google Search using Selenium
Google search can be automated using Python script in just 2 minutes. This can be done using selenium (a browser automation tool). Selenium is a portable framework for testing web applications. It can automatically perform the same interactions that any you need to perform manually and this is a small example of it. Mastering Selenium will help you
3 min read
Search Google Using Python Selenium
Selenium's Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. Through Selenium Python API you can access all functionalities of Selenium WebDriver in an intuitive way. This article illustrates about how to use Selenium Python
1 min read
Search and Play Youtube Music with selenium in Python
Automating YouTube Music with Selenium in Python allows you to easily control and manipulate the playback of songs on the platform. This can be a great way to quickly and easily create a personalized listening experience without having to manually navigate through the website. Here, we will see how we can automate YouTube music with selenium in Pyt
6 min read
text element method - Selenium Python
Selenium’s Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout - Navigating links using get method – Selenium Python. Just being able to go to places isn’t terribly useful. What
2 min read
How to simulate pressing enter in HTML text input with Selenium ?
Selenium is an inbuilt module available in python that allows users to make automated suites and tests. We can build code or scripts to perform tasks automatically in a web browser using selenium. Selenium is used to test the software by automation. Also, programmers can create automated test cases for the software or app using the selenium. By rea
3 min read
Text Searching in Google using Selenium in 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 are going to see how to automate our browser. We can jus
3 min read
Practice Tags :
three90RightbarBannerImg