从 @Find 中使用的 WebElement 获取 By.XPath(how=How.XPATH, using=”//a[.=“Test”]”)

发布于 2025-01-02 01:35:32 字数 514 浏览 2 评论 0原文

出于调试和报告目的,我想从 WebElement 获取 @Find 的使用部分,这可能吗?在调试中,我可以进入 WebElement 并通过其 LocatorHandle 查看其 By.XPATH,因此必须有一种方法可以在代码期间获取它?! 我不能使用 GetAttribute,因为我假设该元素不存在,否则无需在报告中提及它。

为了可视化;)

@FindBy(how = How.XPATH, using = "//a[.='Test']")
private static WebElement btnTest;

public static String GetOrgXpath(WebElement e)
{
    return getByXPath(e); // should return "//a[.='Test']"
}

否则我也接受覆盖 WebElement 并添加一个公共字符串来存储其 xpath(如果可能的话)。我的 Java KungFoo 很弱,所以不知道如何覆盖接口:)

感谢您的帮助

For debugging and reporting purposes, I would like to get the using-part of @Find from a WebElement is this possible? In debug I can go into the WebElement and see its By.XPATH via it's LocatorHandle, so there must be a way to get it during code-time?!
I cannot ofc use the GetAttribute, because I assume the element won't exist, otherwise no need to mention it in the report.

For visualization ;)

@FindBy(how = How.XPATH, using = "//a[.='Test']")
private static WebElement btnTest;

public static String GetOrgXpath(WebElement e)
{
    return getByXPath(e); // should return "//a[.='Test']"
}

otherwise I would also accept to override WebElement and add a public string to store its xpath, if thats even possible. My Java KungFoo is weak, so dunno how to overwrite Interfaces :)

Thanks for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文