问题描述
限时送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:关键词]
发布评论