Selenium - getBodyText() 返回空字符串

发布于 2024-07-23 06:34:58 字数 376 浏览 1 评论 0原文

我试图将整个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伴我老 2024-07-30 06:34:58

我认为您只是忘记刷新 FileWriter

writer.flush()

如果您正确关闭 FileWriter,这当然会自动发生。

I think you just forgot to flush the FileWriter:

writer.flush()

This of course happens automatically if you properly close the FileWriter.

初雪 2024-07-30 06:34:58

首先,我强烈建议您考虑使用 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?

太阳公公是暖光 2024-07-30 06:34:58

感谢大家的帮助。 我认为发生的事情是我没有正确关闭 FileWriter,现在它正在工作。

Thanks everyone for your help. I think what happened was I didn't close the FileWriter correctly, now it's working.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文