【问题标题】:Selenium "return" javascript value not printingSelenium“返回”javascript值不打印
【发布时间】:2014-10-02 12:04:33
【问题描述】:

我正在使用 Selenium 和 Java 进行一些测试。 我必须从 javascript 打印页面 html 的代码非常适合作为警报:

js.executeScript("alert($('html').html());");

但是,当我使用 return 时,Eclipse 控制台中没有任何内容:

js.executeScript("return $('html').html();");

我做错了什么,如何打印(使用 System.out.print)从 Javascript 返回的 html 结果?谢谢,不,我不想使用源代码。

【问题讨论】:

  • 如果您为js.executeScript 调用分配一个值并打印该值会发生什么? (即System.out.println(js.executeScript(..))
  • @AnthonyForloney 这也有效!
  • 很高兴听到!问题可能是内容确实被返回但没有得到适当的处理(即,没有通过System.out.println 调用打印)。

标签: java javascript selenium


【解决方案1】:

我相信你可以使用driver.getPageSource() 得到你想要的结果。

System.out.println(driver.getPageSource());

【讨论】:

  • 我知道我说过我不想使用有问题的源,但这实际上适用于我试图检索的页面部分,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-09
  • 2014-02-12
  • 1970-01-01
  • 2016-05-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多