如何在 Junit 框架中使用 seleniumRC 动态更改 elementid

发布于 2024-10-05 18:20:42 字数 404 浏览 0 评论 0原文

我正在尝试自动化工作流程。在此,我需要单击位于表的任何行中的链接。事情是所有行中可用的所有链接都具有相同的元素 ID,并且在源代码中我有一个 java像“(“Element ID”@Onclick..java脚本****:)这样的脚本......点击它后,这里将一个表单连接到另一个表单通过在java脚本代码中输入一些值来形成表单,并且java脚本中的一个值也会动态变化。我现在如何单击该链接?有没有使用xpath等的解决方案...根据CSS classID或其他方式精确单击该链接所以...请帮我解决...主要问题是...行中的所有链接都具有相同的元素 ID 和动态更改的 java 脚本。 我正在尝试使用 selenium.focus() 和 selenium.clickAndwait()。但这些都是无助的。因为它无法仅识别链接 ID。

I am trying to automate a work flow process .In this,I need to click on a link positioned in any of the rows of table.Thing is all links available in all rows have same element ID and in the source code I have a java script like " ("Element ID" @ Onclick..java script****:).....SO here after clicking it is connecting one form to another form by inputting some value in java script code and also one value in java script dynamically changes.How do I click on that link now?Is there any solution using xpath or so...to exactly click on that link based on CSS classID or so...Please help me out..Main problem is...all links in rows have same element ID and dynamically changing java script .
I am trying to use selenium.focus() and selenium.clickAndwait().But these are helpless.as it is not able to identify link ID only.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抹茶夏天i‖ 2024-10-12 18:20:42

最好的方法是使用 xpath。

//*[@onclick='javascript'] 这样的东西可以工作,但这可能会使测试变得非常不稳定,因为如果内联 javascript 发生变化,或者如果它优先于元素的 addEventListener 被删除。

//*[@class='cssClass'] 这样的东西会起作用。我认为您需要与开发人员交谈并要求他们帮助使其更易于测试。

The best way to do this would be with xpath.

Something like //*[@onclick='javascript'] will work but this can make the tests extremely flaky because if the inline javascript changes or if its removed in preference of addEventListener to the element.

something like //*[@class='cssClass'] will work. I think that you will need to speak to the developers and ask them to help make it more testable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文