Selenimum 使用 Selenium 定位属性并单击与图像关联的动态链接

发布于 2024-09-12 05:35:06 字数 311 浏览 2 评论 0原文

我是 Selenium 和编码的新手。我想做的是单击动态链接。这是场景。

我必须在具有多个链接的 div 中找到一个动态链接。

我要单击的链接具有 myimage 属性,并且链接始终会有所不同。 div 中可以有 N 个链接,并且某些链接不具有 myimage 属性。

我可以使用 XPath 定位 div,但在 div 中找不到我想要的链接。

简而言之,我想浏览 div 中的动态链接列表,找到具有 myimage 类的链接并单击它。

有人可以建议参考或提供有关如何使用 C# 使用 Selenium 执行此操作的代码片段吗?

I am new to Selenium and coding. What I am trying to do is click a dynamic link. Here is the scenario.

I have to find a dynamic link in a div that has multiple links.

The link I want to click has the myimage attribute and the link will always be different. There can be N-links in the div and some of the links won't have the myimage attribute.

I can locate the div using XPath, but I am having trouble finding the link I want in the div

In short, I want to look through the list of dynamic links in a div, find a link that has the myimage class and click it.

Can someone suggest a reference or provide a code snippet on how to do this with Selenium using C#?

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

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

发布评论

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

评论(1

最单纯的乌龟 2024-09-19 05:35:06

我假设您拥有最新版本的 selenium。

您所需要做的就是扩展 div 的 XPath 以包含具有属性的链接。我还没有在代码中尝试过这个,但应该可以工作:

Selenium.Click("xpath=//a[@class='myimage']")

检查 这篇文章了解更多详细信息

I'm assuming that you have the latest version of selenium.

All you need is to extend the XPath you have for the div to include the link with the attribute. I haven't tried this in code but should work:

Selenium.Click("xpath=//a[@class='myimage']")

Check this article for more details

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