需要验证JS脚本中是否存在关键字google_conversion_id = 2586489987;
。试过下面的代码。无法从JS脚本中捕获关键字。可以让我如何验证源代码中存在的JS脚本中的关键字吗?
boolean a =driver.getPageSource().contains("2586489987"));
System.out.println(a);
if (a){
System.out.println("Text is Present on page "+driver.getCurrentUrl());
}
else{
System.out.println("Text is NOT Present on page "+driver.getCurrentUrl());
fail =true;
driver.close();
}
JS脚本如下。我需要验证JS中存在google_conversion_id = 2586489987
<script type="text/javascript">
var google_conversion_id = 9846489987;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
</script>
答案 0 :(得分:1)
而不是检查源代码为什么不能获得真正的JS值?
result = driver.executeScript("return google_conversion_id");