- 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 read test data from an excel sheet and use it to test facebook login in Selenium Webdriver?
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 – email@example.com 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 = b.active #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") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.facebook.com/") #identify element l = driver.find_element_by_id("email") #enter email obtained from excel l.send_keys(email) m = driver.find_element_by_id("pass") #enter password obtained from excel m.send_keys(passw) #get values entered s = l.get_attribute("value") t = m.get_attribute("value") print("Email is: ") print(s) print("Password is: ") print(t) #browser quit driver.quit()
- How can we read data from an excel sheet in Selenium Webdriver?
- How to run Selenium WebDriver test cases in Chrome?
- Test if an element is focused using Selenium Webdriver.
- Test if element is present using Selenium WebDriver?
- How to create train, test and validation samples from an R data frame?
- How to run multiple test cases using TestNG Test Suite in Selenium?
- How test runner prioritize test classes for execution in Selenium?
- How to automate gmail login process using selenium webdriver in java?
- Write a Python program to read an Excel data from file and read all rows of first and last columns
- Facebook Login using Python
- How to use shapiro wilk test to check normality of an R data frame column?
- How to include and exclude test methods from a set of test cases in Cucumber?
- How to incorporate and remove test methods from execution from a collection of test cases in TestNG?
- How to create a file, write data into it and read data from it on iOS?
- How to create nested test suites for Selenium IDE?