复制文本文件内容到文本区域

huangapple 未分类评论62阅读模式
英文:

Copy text file content into text area

问题

//从文本文件中读取内容
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String line;
String xml_file = "";
while((line = br.readLine()) != null){
xml_file += line;
}

//驱动代码
element.sendKeys(xml_file)

这段代码实际上是有效的,但问题是将内容写入文本区域大约需要10分钟。是否有其他可能的方法来做到这一点?

英文:

I have to copy and paste the huge content in a text file into text area of my application.

//Read content from text file
FileReader fr = new FileReader(file);
		BufferedReader br = new BufferedReader(fr);
		String line;
		String xml_file = "";
		while((line = br.readLine()) != null){
			xml_file += line;
		}

//Driver code
element.sendKeys(xml_file)

This code actually works but the problem is its taking around 10 mins to write the content into text area.

Is there any other possible ways to do this?

答案1

得分: 0

我使用了 JS,只需要几秒钟就将数据写入了文本区域。

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].value='" + xml_file + "';", driver.findElement(By.cssSelector("#id")));
英文:

I used JS which took fraction of seconds to write the data into textarea

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].value='"+ xml_file+"';", driver.findElement(By.cssSelector("#id")));

huangapple
  • 本文由 发表于 2020年7月28日 21:22:01
  • 转载请务必保留本文链接:https://java.coder-hub.com/63135154.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定