How to read Invalid Data | Selenium Forum
M
Posted on 17/07/2016
I am failing to read invalid data from excel.Could you please let me know how to read invalid data.

package selenium14;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class loginAgain {
@Test(dataProvider="getData")
public void login(String Browser,String Username,String Password,String Expected){
System.out.println(Username+"__"+Password);
String caseA="Sorry, Google doesn't recognize that email.";
String caseB="Please enter your email.";
String caseC="Please enter your password.";


if(Browser.equals("Firefox")){
WebDriver driver=new FirefoxDriver();
driver.get("http://gmail.com");
driver.findElement(By.xpath("//*[@id='Email']")).sendKeys(Username);
driver.findElement(By.xpath("//*[@id='next']")).click();
driver.findElement(By.xpath("//input[@id='Passwd']")).sendKeys(Password);
driver.findElement(By.xpath("//*[@id='next']")).click();
driver.findElement(By.xpath("//*[@id='signIn']")).sendKeys(Keys.ENTER);

String actualError= driver.findElement(By.xpath("//span[@class='error-msg']")).getText();
System.out.println(actualError);

if(Expected.equals(caseA))
Assert.assertEquals(actualError, caseA);
if(Expected.equals(caseB))
Assert.assertEquals(actualError, caseB);
if(Expected.equals(caseC))
Assert.assertEquals(actualError, caseC);
}
}

@DataProvider
public Object[][] getData(){
Xls_Reader xls=new Xls_Reader("C:\\Users\\sanja\\Desktop\\webuy.xlsx");
int rows=xls.getRowCount("sheet3");
int cols=xls.getColumnCount("sheet3");
Object[][] data=new Object[rows-1][cols];
for(int rNum=2;rNum<=rows;rNum++){
for(int cNum=0;cNum<cols;cNum++){
data[rNum-2][cNum]=xls.getCellData("sheet3", cNum, rNum);
}
}
return data;
}

}

-----No such element exception I am using the corect xpath of password.-----Could you please tell how to read invalid data.In real time do we have to read like this

excel data---
Browser Username Password Expected
Firefox jyosh.ma Sorry, Google doesn't recognize that email.
Firefox Please enter your email.
Firefox jyosh.maddy@gmail.com Please enter your password.

Thank you in advance

M
Replied on 18/07/2016

what are you trying to do?


M
Replied on 18/07/2016

Reading invalid data and blank data from excel.


M
Replied on 18/07/2016

you cannot read blank data.


M
Replied on 18/07/2016

you cannot read blank data. it will give you an error.