java - 在 Selenium 中定位脚本

标签 java selenium

有人可以帮我编写代码来在selenium(java)中找到这个元素吗?我需要找到它并获取文本。

<script type="text/javascript" language="javascript">
    var _kc={"ticket":"","currency":"EUR","market":"RO","customerData":"8","oddsFormat":"decimal","locale":"en_GB","streamingAllowedForPlayer":true,"racingMode":false,"playerId":"","enableFreeBets":false};
</script>

截图:enter image description here

我想使用 AssertEquals 来检查该脚本是否存在于网页中。

最佳答案

您可以使用以下方式从脚本文本中获取文本:

 String scriptText =  driver.findElement(By.xpath("//div[@id='InnerContentDiv']//script")).getAttribute("innerText");

之后您可以使用此文本进行断言。

关于java - 在 Selenium 中定位脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51132693/

相关文章:

java - 使用 Selenium WebDriver 获取 Firebug 控制台输出

python - Django + Pytest + Selenium

java - Hibernate JPA 父子映射

java - 在 x 分钟做某事,然后每隔 n 分钟再做一次

java - 如何在java中对一个数组列表进行排序并以相同的顺序设置另一个列表

java - 为 Oauth 和 Http Basic 身份验证配置 Spring Security

java - 并发只写事务

Python 无法使用 Selenium 识别表格单元格中的文本

python - 用 Selenium python 刮取产品颜色

google-chrome - centos 6.5 上的 chromedriver 无法运行