Selenium div 属性不断变化,我如何找到这个元素?

编程入门 行业动态 更新时间:2024-10-28 07:26:58
本文介绍了Selenium div 属性不断变化,我如何找到这个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试使用 Selenium 和 Java 查找元素,问题是元素的 id、类和名称总是递增,因此我无法使用 selenium 找到它.以下是我目前正在尝试的内容:

I am trying to find an element with Selenium and Java, the problem is that the element's id, class, and name always increment so I am not able to find it with selenium. Below is what I am currently trying:

WebElement field = driver.findElement(By.xpath("//input[contains(@linkText, 'Broadcast copy')]"));

在我的 html 文件中,这些是不断变化的属性:

In my html file these are the attributes that keeps changing:

id="files[%2Fopt%240%2Frules%2F%2F000102%2.xml][%2Fcluster%2Fname]"

name="files[%2Fopt%240%2Frules%2F%2F000102%2.xml][%2Fcluster%2Fname]" 

value="copy (Cluster 102)"

整个 html

<tbody>
   <tr class='rowOdd'>
      <td><b>Name</b></td>
      <td> <input type='text' data-validation='required validate-name-unique validate-name-not-empty' size='65' id='files[%2Fopt%240%2Frules%2F%2F000102%2Fcluster.xml][%2Fcluster%2Fname]' name='files[%2Fopt%240%2Frules%2F%2F000102%2Fcluster.xml][%2Fcluster%2Fname]' value='copy (Cluster 102)' /> </td>

这些总是递增,我无法访问 html 文件来更改任何内容.所以我的问题是如何找到这个输入元素?提前致谢.

These always increment and I have no access to the html file to change anything. So my question is how can I find this input element? Thanks in advance.

更新

我收到错误:

Unable to locate element:{"method":"id", "selector":"files[.*][.*]"}

推荐答案

由于 id、class 和 css 的属性在不断变化,因此 'data-validation' 一直保持不变.所以下面的代码对我有用.

Since the attributes of id, class, and css were constantly changing, 'data-validation' was one that stayed the same all the time. So the code below worked for me.

driver.findElement(By.xpath("//input[@data-validation='required validate-name-unique validate-name-not-empty']"));

这篇关于Selenium div 属性不断变化,我如何找到这个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 09:20:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1132409.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   元素   Selenium   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!