- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 data from a specific cell value (say 2nd row and 2nd column) inside a table in Selenium with python?
We can extract values from a specific cell (say 2nd row and 3rd column) inside a table in Selenium. First of all we need to locate the cell with the help of xpath locator.
Since the row and column numbers are given, we can create a customized xpath with the help of indexes specified for both <tr> and <td> tags. 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.
So to get the value at the second row and second column, we have to mention the row as tr and the third column will be identified as td.
The html code snippet of a table header is as described below −
Coding Implementation for getting value from second row and second column.
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() # to get the data from 2nd row and 2nd column directly val = driver.find_elements_by_xpath("//table/tbody/tr/td").text # print the value in console print(val) #to close the browser driver.close()
- How to get the 2nd highest value from a table with Student Score?
- How to get the value in a particular cell inside the worksheet in Selenium with python?
- How to write value inside a cell in a worksheet in Selenium with python?
- How to get the values of a particular row in a table in Selenium with python?
- MySQL insert a value to specific row and column
- How to retrieve the value from a table cell with TableModel in Java?
- Get only a single value from a specific MySQL row?
- Find the 2nd largest number in a Java array.
- Find the 2nd smallest number in a Java array.
- How to get all the values including the headers inside a table in a page in Selenium with python?
- How to get a value from the cell of a Pandas DataFrame?
- Get all the tables from a MySQL database having a specific column, let’s say xyz?
- How to exclude a specific row from a table in MySQL?
- How to get the count of a specific value in a column with MySQL?
- Rearrange An Array In Order – Smallest, Largest, 2nd Smallest, 2nd Largest,. Using C++