- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to count the number of occurrences of a particular text inside a table in a page in Selenium with python?
We can count the number of occurrences of a particular text inside a table in Selenium. First of all we need to locate the element by xpath. In xpath, we have a particular text() function that identifies elements based on the visible text on the screen.
Then we have to use find_elements method to get the list of matching elements having the text we are looking for on the page. Finally we need to get the size of that list with the help of the len function of the list.
This will give the number of occurrences of a particular text inside a table.
Syntax
driver.find_elements_by_xpath("//td[text()='Tutorialspoint']")
Example
Coding Implementation to get the count of occurrences of a text inside a table.
from selenium import webdriver #browser exposes an executable file #Through Selenium test we will invoke the executable file which will then #invoke actual browser driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") # to maximize the browser window driver.maximize_window() #get method to launch the URL driver.get("https://www.tutorialspoint.com/plsql/plsql_basic_syntax.htm") #to refresh the browser driver.refresh() # identifying the text keyword inside the table dta = driver.find_elements_by_xpath("//td[text()='keyword']") # len method is used to get the count of occurrences print(len(dta)) #to close the browser driver.close()
- Related Articles
- How to count the number of checkboxes in a page in Selenium with python?
- How to count the total number of tables in a page in Selenium with python?
- How to count the number of rows in a table in Selenium with python?
- How to count the total number of radio buttons in a page in Selenium with python?
- How to get all the values including the headers inside a table in a page in Selenium with python?
- How to count the number of frames in a page in Selenium?
- How to get the screenshot of a particular element in the page in Selenium with python?
- How to get the values of a particular row in a table in Selenium with python?
- How to count the total number of links in a page in Selenium?
- How to get the value in a particular cell inside the worksheet in Selenium with python?
- How to count the number of headers in a web table in Selenium?
- Count occurrences of a char in a text file
- How to count total number of occurrences of an object in a Python list?
- How to get the complete screenshot of a page in Selenium with python?
- How to count the number of occurrences of a character in a string in JavaScript?

Advertisements