- 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 get the values of a particular row in a table in Selenium with python?
We can get the values of a particular row in a table in Selenium. The rows of a table are represented by <tr> tag in html code. The data in each row is enclosed with the <td> tag in html. Thus a <td> tag’s parent is always a <tr> tag.
The logic is 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 <td> is not normally present in the first row of the table. In place of <td>, there is the <th> tag.
Syntax
driver.find_elements_by_xpath("//table/tbody/tr[2]/td")
The html code snippet of a table header is as described below −
Example
Coding Implementation to get the second row data.
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 from row2 having <td> tag rwdata = driver.find_elements_by_xpath("//table/tbody/tr[2]/td") # len method is used to get the size of that list print(len(rwdata)) for r in rwdata: print(r.text) #to close the browser driver.close()
- Related Articles
- How to get all the values of a particular row based on a condition in a worksheet in Selenium with python?
- How to get all the values of a particular column based on a condition in a worksheet in Selenium with python?
- How to get the screenshot of a particular element in the 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 get all the values in a worksheet in Selenium with python?
- How to get the value in a particular cell inside the worksheet in Selenium with python?
- How to count the number of occurrences of a particular text inside a table in a page in Selenium with python?
- How to get the data from a specific cell value (say 2nd row and 2nd column) inside a table in Selenium with python?
- Get the number of rows in a particular table with MySQL
- In MySQL how to replace all NULL values in a particular field of a particular table?
- How to get values of all rows in a particular column in openpyxl in Python?
- Screenshot of a particular element with Python Selenium in Linux
- How to select particular range of values in a MySQL table?
- How to count the number of rows in a table in Selenium with python?
- How to get the complete screenshot of a page in Selenium with python?

Advertisements