我正在尝试使用功能登录 gmail。我正在从 Excel 表中传递用户名。问题是我的代码返回值但没有在文本框中输入。它不会抛出任何错误,只是返回空异常。
请帮帮我,我是 selenium webdriver 的新手,真的不知道下一步该做什么,因为它也没有显示任何错误。
public class gmail
{
public static WebDriver driver;
public static void main(String[] args) throws IOException, InterruptedException
{
File file1 = new File("C:\\Selenium\\IEDriverServer_Win32_2.35.3\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file1.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.get("www.gmail.com");
FileInputStream file = new FileInputStream(new File("D:\\Automation\\Selenium\\New Folder\\Demo\\Book2.xls")); // Path of the excel where the keywords and data was mentioned
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheetAt(0);
int d= sheet.getLastRowNum();
System.out.println(d);
for (int i=1;i<=d;i++)
{
Cell cell1=null;
cell1=sheet.getRow(i).getCell(0);
System.out.println(cell1);
if (cell1.getStringCellValue().contains("text"))
{
Cell cell2=null;
cell2=sheet.getRow(i).getCell(1);
System.out.println(cell2);
stg(cell2); //calling function
}
}
}
public static void stg(Cell cell2) throws InterruptedException
{
WebElement un1=driver.findElement(By.name("Email"));
System.out.println(un1);
un1.sendKeys(cell2.getStringCellValue());
}
}
//This is the Output which i am getting:
1
text
选择测试10j
Exception in thread "main" java.lang.NullPointerException
at Excel.gmail.stg(gmail.java:63)
at Excel.gmail.main(gmail.java:53)