Selenium - getBodyText() 返回空字符串
我试图将整个 html 页面与 getBodyText 保存到字符串中,然后将其写入文件(.txt)。 但是当我检查该文件时,它是空的。 这是我的代码:
String store_report = selenium.getBodyText();
File f = new File("C:/folder/" + "report" + ".txt");
FileWriter writer = new FileWriter(f);
writer.append(store_report);
System.out.println("Report Created is in Location : " + f.getAbsolutePath());
I'm trying to save the whole html page with getBodyText into a String and then write it to a file (.txt). However when I check the file, it's empty. Here's my code:
String store_report = selenium.getBodyText();
File f = new File("C:/folder/" + "report" + ".txt");
FileWriter writer = new FileWriter(f);
writer.append(store_report);
System.out.println("Report Created is in Location : " + f.getAbsolutePath());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为您只是忘记刷新
FileWriter
:如果您正确关闭
FileWriter
,这当然会自动发生。I think you just forgot to flush the
FileWriter
:This of course happens automatically if you properly close the
FileWriter
.首先,我强烈建议您考虑使用 try/finally 块来关闭 FilreWriter :)
您能否确认您看到 getBodyText() 命令实际上被发送到 Selenium 服务器? 您是否见过它在浏览器中嵌入的命令日志中运行? 您有重现该问题的公共 URL 吗?
Well first, I'd strongly encourage you to consider a try/finally block which closes that FilreWriter :)
Can you confirm you see the getBodyText() command actually being sent to the Selenium server? Have you seen it run in the command log that is embedded inside the browser? Do you have a public URL that reproduces the problem?
感谢大家的帮助。 我认为发生的事情是我没有正确关闭 FileWriter,现在它正在工作。
Thanks everyone for your help. I think what happened was I didn't close the FileWriter correctly, now it's working.