我有以下格式的文本文件: UserName
Password
两个单独的行。 我想输入用户名到用户名字段(很明显),并只输入密码相同的密码字段。 我的测试曾经为每个元素定义了一个String
元素,这一切都很好,因为我只是简单地调用String元素。问题是我无法检查我的代码,因为它有我的个人活动目录登录信息。所以我试图从文本文件中读取它。我有以下的代码来做到这一点:读取用户名和密码从文本文件
try
{
FileInputStream fstream = new FileInputStream(".../Documents/userInfo.txt");
// Use DataInputStream to read binary NOT text.
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
int count = 0;
strLine = br.readLine();
count++;
while(strLine!= null)
{
//Enter userName
WebElement userName = driver.findElement(By.id("username"));
userName.clear();
userName.sendKeys(strLine);
System.out.println(strLine);
strLine = br.readLine();
count++;
//Enter Password
WebElement password = driver.findElement(By.id("pword"));
password.clear();
password.sendKeys(strLine);
System.out.println(strLine);
}
in.close();
br.close();
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
,我运行到的是,它输入用户名和密码,然后贯穿一遍只有在密码投入User Name字段的问题。我知道这可能是我看起来很简单的事情。请帮忙。
这工作很好,是的,我只有一个用户名/密码 – DarthOpto 2013-02-15 23:17:41