因此,我已经在facebook上找到了textbox,并向一个人发送了一条消息。现在,我想看看是否可以创建一个循环来一次发送多个消息。我现在的问题是我有一个for循环:
for (int i = 0; i < 20; i++) {
messageBox.sendKeys("My friend's name " + i + " ");
messageBox.sendKeys(Keys.ENTER);
}但是,我只能这样做一次。因此,它将打印"My friend's name0“,然后停止。Java说:元素没有附加到页面文档。
我假设因为我发送了消息,所以检查元素的某些部分已经更改了?有没有办法解决这个问题?
发布于 2016-02-24 15:25:53
从Excel工作表中获取好友的姓名
创建一个从excel文件中获取数据的方法:
public static void fn_FetchExcelData(String FilePath,String ColumnName) throws IOException{
String WbookPath=FilePath;
Workbook WBookObj=fn_GetWorkbook(FilePath);
Sheet SheetObj=WBookObj.getSheetAt(0);
Row FstRowObj=SheetObj.getRow(0);
int cellCount=FstRowObj.getLastCellNum();
int columnNumber=0;
ArrayList<String> AL=new ArrayList<String>();
for(int j=0; j<cellCount;j++){
if(FstRowObj.getCell(j, Row.CREATE_NULL_AS_BLANK).getStringCellValue().trim().equalsIgnoreCase(ColumnName)){
columnNumber=j;
break;
}
}
int rowcnt=SheetObj.getLastRowNum();
for(int i=1;i<=rowcnt;i++){
Cell fstcellObj=SheetObj.getRow(i).getCell(columnNumber, Row.CREATE_NULL_AS_BLANK);
String ColumnVal=fstcellObj.getStringCellValue();
AL.add(ColumnVal);
call excel method & use it
fn_FetchExcelData("Your excel data path");
int j;
int size = AL.size();
for(j=0;j<size;j++)
{
System.out.println(AL.get(j));
messageBox.sendKeys(AL.get(j));发布于 2015-07-02 04:27:06
不要紧,我想出来了,我只是加了
WebElement messageBox = driver.findElement(By.xpath("//textarea[@class='uiTextareaAutogrow _552m']"));
wait.until(ExpectedConditions.visibilityOf(messageBox));再回到循环中,它就起作用了。然而,它是非常慢的。
https://stackoverflow.com/questions/31170873
复制相似问题