How to read test data from an excel sheet and use it to test facebook login in Selenium Webdriver?

SeleniumAutomation TestingTesting Tools

We can read test data from an excel sheet and use it to test Facebook login with Selenium webdriver in Python. We can access excel with Python with the help of the OpenPyXL library.

To install this library, we have to run the command - pip install openpyxl. Besides, we have to add the statement import openpyxl in our code. To start with, we have to load the excel workbook with the help of the load_workbook method.

The path of the workbook is passed as a parameter to this method. Then we have to determine its active sheet by applying the sheet method on the loaded workbook object.

To test the Facebook login page, we need to have the email and password of the user and this data is saved in an excel workbook as shown in the below image. The email – is at cell (address: row=2, column=1) and password – test123 is at cell(address: row=2, column=1).

To read these data, we shall use the cell method on the active sheet. The row and column numbers are passed as parameters to this method. Then the value method is applied on those particular cell addresses to read values within it.


import openpyxl
from selenium import webdriver
#configure workbook path
b = openpyxl.load_workbook("C:\\Data.xlsx")
#get active sheet
sht =
#get cell address of email within active sheet
e = sht.cell (row = 2, column = 1)
#get cell address of password within active sheet
p = sht.cell (row = 2, column = 2)
#get values
email = e.value
passw = p.value
#set chromodriver.exe path
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
#launch URL
#identify element
l = driver.find_element_by_id("email")
#enter email obtained from excel
m = driver.find_element_by_id("pass")
#enter password obtained from excel
#get values entered
s = l.get_attribute("value")
t = m.get_attribute("value")
print("Email is: ")
print("Password is: ")
#browser quit


Published on 08-Apr-2021 11:17:31