gpt4 book ai didi

java - 在 Selenium 中定位脚本

转载 作者:行者123 更新时间:2023-12-02 11:03:52 24 4
gpt4 key购买 nike

有人可以帮我编写代码来在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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com