

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 all the values of a column in a worksheet in Selenium with python?
We can get all the values of a column in a worksheet in Selenium. Excel is a spreadsheet which is saved with the .xlsx extension. An excel workbook has multiple sheets and each sheet consists of rows and columns.
Out of all the worksheets, while we are accessing a particular sheet that is called as an active sheet. Each cell inside a sheet has a unique address which is a combination of row and column numbers.
The column number starts from alphabetic character A and row number starts from the number 1. A cell can contain numerous types of values and they are the main component of a worksheet.
To work with excel in Selenium with python, we need to take help of OpenPyXL library. This library is responsible for reading and writing operations on Excel, having the extensions like xlsx, xlsm, xltm, xltx.
To install OpenPyXL library, we have to execute the command pip install openpyxl. This is because OpenPyXL does not come by default with python. After this we should import openpyxl in our code and then we should be ready to interact with excel.
To get the values from a particular column, first of all we need to load the entire workbook by specifying the path where it is located. This is achieved with load_workbook() method. Next we need to identify the sheet with the help of the sheet name.
And also we need to identify the column address for which we want to retrieve all the values. Then we need to iterate through all the cells in that specific column and get the values with the help of value method.
Syntax
wrkbk = load_workbook("C:\\work\\SeleniumPython.xlsx") # to identify the sheet with name sh = wrkbk["Sheet1"]
Example
Coding Implementation to get all the values from a particular column.
import openpyxl # load excel with its path wrkbk = load_workbook("C:\\work\\SeleniumPython.xlsx" sh = wrkbk["Sheet1"] # to iterate through cells in Column A and print value in console for c in sheet['A']: print(c.value)
- Related Questions & Answers
- How to get all the values 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 all the values of a particular row based on a condition 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 create a worksheet and write some values in it in Selenium with python?
- How to get the maximum number of occupied rows and columns in a worksheet in Selenium with python?
- How to write value inside a cell in a worksheet 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 the values of a particular row in a table in Selenium with python?
- How to get a list of all the values from a Python dictionary?
- Python - Remove a column with all null values in Pandas
- Get the sum of last 3 digits from all the values in a column with MySQL
- How to get the complete screenshot of a page in Selenium with python?
- How to get all options of a dropdown using Python Selenium webdriver?
- How to extract the column headers in a table in Selenium with python?