- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 rows in a table in Selenium with python?
We can count the total number of rows in a table in Selenium. The rows of a table are represented by <tr> tag in html code. To get all the rows, we shall use the locator xpath and then use find_elements_by_xpath method. The list of rows will be returned. Next we need to compute the size of the list with the help of len method.
The html code snippet of a table row count is as described below −
Syntax
driver.find_elements_by_xpath("//table/tbody/tr")
Example
Code Implementation for getting row count.
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 number of rows having <tr> tag rows = driver.find_elements_by_xpath("//table/tbody/tr") # len method is used to get the size of that list print(len(rows)) #to close the browser driver.close()
- Related Articles
- How to count number of rows in a table with jQuery?
- How to count the number of occurrences of a particular text inside a table in a page in Selenium with python?
- How to count the number of checkboxes in a page in Selenium with python?
- How to count the number of headers in a web table in Selenium?
- How to count the total number of links in Selenium with python?
- How to count the total number of frames in Selenium with python?
- How to count the total number of tables in a page in Selenium with python?
- How to count the total number of radio buttons in a page in Selenium with python?
- Count number of rows in each table in MySQL?
- How to get the maximum number of occupied rows and columns in a worksheet in Selenium with python?
- Fastest way to count number of rows in MySQL table?
- How to get number of rows in a table without using count(*) MySQL query?
- How to count number of columns in a table with jQuery
- How can we use MySQL SELECT statement to count number of rows in a table?
- How to count the number of frames in a page in Selenium?

Advertisements