import java.io.FileInputStream;
import jxl.Sheet;
import jxl.Workbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox. FirefoxDriver;
import org.testng.annotations. BeforeClass;
import org.testng.annotations.Test;
public class WebDriverExcel
{
private WebDriver driver;
@BeforeClass
public void Startup()
{
driver = new FirefoxDriver();
}
@Test
public void Login() throws Exception
{
FileInputStream fi=new FileInputStream("C:\\Users\\ neeraj\\Desktop\\test.xls");
Workbook w=Workbook.getWorkbook(fi);
Sheet s=w.getSheet(0);
driver.get("https://mail. google.com/mail/");
{
for (int i = 1; i < s.getRows(); i++)
{
for (int j = 0; j < s.getColumns(); j++)
{
//Read data from excel sheet
String s1 = s.getCell(j,i).getContents();
System.out.println("Usernam"+ s1);
String s2 = s.getCell(++j,i).getContents() ;
driver.findElement(By.id(" Email")).sendKeys(s1);
driver.findElement(By.id(" Email")).clear();
System.out.println("Password"+ s2);
driver.findElement(By.id(" Passwd")).sendKeys(s2);
driver.findElement(By.id(" Passwd")).clear();
driver.findElement(By.id(" signIn")).click();
}
}
}}
}
Good one Neeraj!!
ReplyDeleteKeep up the good work!!
Thanks Rakesh..!!
DeleteI hope you ppl like the blog and help in Contributing to Tester's Community...:)
Hi Neeraj Ji,
ReplyDeleteThx for the wonderful site.
Thanks Madiraju :)
ReplyDeleteIts all for testing Community, join this blog and share the content among friends and testers.
1.Write Excel + JXL API [Web Driver]
I want added at time multiple rows and columns.
EMPID
EMPNAME
EMPADDRESS
10
WEB
HYD
20
DRIVER
BANG
30
SELENIUM
CHENNAI
public static void main(String[] args) throws Exception {
File f = new File("src/pkg/xyz.xls"); //new Xl sheet create
FileOutputStream ff = new FileOutputStream(f);
WritableWorkbook book = Workbook.createWorkbook(ff);
WritableSheet sheet = book.createSheet("Sheet1", 0); //CreateSheet("SheetName","index")
Label description = new Label(0, 0, "EMPID"); //Label(ColNumber-1,RowNumber-1,Data)
sheet.addCell(description);
Label orderNo = new Label(1, 0, "EMPNAME");
sheet.addCell(orderNo);
Label amount = new Label(2, 0, "ADDRESS");
sheet.addCell(amount);
book.write();
book.close();
}}
NOTE: I have using addCell one-by-one but,added at time multiple rows and columns.