gpt4 book ai didi

java - WebDriver - 查找与元素相对应的文本

转载 作者:行者123 更新时间:2023-12-01 23:47:06 25 4
gpt4 key购买 nike

这个要求看起来很愚蠢,但我想看看我们是否可以自动验证 UI 中的元素。

Req:我需要断言与“Name:”字段对应的输入元素是一个文本框。

使用 Selenium RC,我可以做到:

assertTrue(selenium.getAttribute("//label[normalize-space(text()='Name:')]/following-sibling::input@type").equals("text"))

这也可以使用 webdriver,但是我们有更简单的方法吗?

最佳答案

在 webdriver 中更容易阅读:

假设 selenium 是您的驱动程序对象,您可以执行以下操作:

String elementAttribute = selenium.findElement(By.xpath("//yourXpathHere")).getAttribute("Type");
if (elementAttribute.equals("text") //success!
else //fails!

关于java - WebDriver - 查找与元素相对应的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16860885/

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