gpt4 book ai didi

html - 使用 Selenium 查找具有流体 xpaths 的元素

转载 作者:太空宇宙 更新时间:2023-11-04 02:24:11 24 4
gpt4 key购买 nike

从下面的 HTML 代码中,我试图选择 <input class="cs-autocomplete-input" tabindex="">但是,使用 Selenium WebDriver,我似乎无法做到,因为元素具有流动的 ID。我怎样才能找到这些元素?我不能使用 By.className("cs-autocomplete-input")因为网页中有多个具有该类名称的元素。

<div class="content">
<div id="fluid-id-bhlpjo3p-1026">
<input type="button" class="csc-repeatable-add-bhlpjo3p-1022 cs-repeatable-add" value="+">
<ul class="cs-repeatable">
<li class="csc-repeatable-repeat-bhlpjo3p-1022 clearfix cs-repeatable-repeat show">
<input type="radio" class="csc-repeatable-primary-bhlpjo3p-1022 show cs-repeatable-primary" name="primary-fields.sponsors" value="true">
<input type="text" class="csc-exhibition-sponsor cs-repeatable-content" id="repeat::.csc-exhibition-sponsor" name="repeat::.csc-exhibition-sponsor" style="display: none;">
<input class="cs-autocomplete-input" tabindex="">
<a href="#" class="cs-autocomplete-closebutton" title="Cancel edit, and return this field to the most recent authority value" style="display: none;"></a>
<input type="button" value="" class="csc-repeatable-delete-bhlpjo3p-1022 cs-repeatable-delete" disabled="">
</li>
</ul>
</div>

不确定这是否有帮助,但这个 div 的 xpath 是 //*[@id="primaryTab"]/div/div[3]/div[1]/div[2]/div[2]/div[1]/div/div[2]

最佳答案

你可以尝试这样的事情:

browser.findElement(By.id("primaryTag")).findElement(By.cssSelector(".cs-autocomplete-input[tabindex='']"))

这是实际的 CSS。

#someId .my-input[tabindex=''] {
background: red;
}

/* styles for example readability — ignore */
input {
display: block;
margin-bottom: 1em;
padding: 0.5em 1em;
}
<div id="someId">
<input class="my-input" tabindex="3" type="text" value='not me' />
<input class="my-input" tabindex="3" type="text" value='not me' />
<input class="my-input" tabindex="" type="text" value=' me' />
<input class="my-input" tabindex="3" type="text" value='not me' />
<input class="my-input" tabindex="" type="text" value='me' />
</div>

关于html - 使用 Selenium 查找具有流体 xpaths 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37603346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com