当使用 selenium 使用 Xpath 查找元素标签时,它使用从 chrome 为该元素复制的 xpath 工作,这是为了测试它是否工作。由于每次打开网页时 id 元素都会更改,我知道这会导致我的 Web 自动化程序出错,现在从同一个标签中,我正在使用 class 元素,因为每次打开网页时它都不会改变,但是 Selenium根本找不到那个元素。当我将 xpath 中的元素更改为具有来自 xpath 的相对名称的类时,我最初是从 webbroswer 复制和测试的。可能是什么问题?
这是我想要访问的 html 源代码和 Xpath 的示例:
<div class="popover fade right in" role="tooltip" id="popover784483" style="top: -9px; left: 328.5px; display: block;">
<div class="arrow" style="top: 88.9423%;"></div>
<h3 class="popover-title">
<font style="vertical-align: inherit;">
<font style="vertical-align: inherit;">Member details</font>
</font>
</h3>
<div class="popover-content">
<img class="center-block" src="http://api.vdarts.net:8080/picture/portrait/default.png" style="max-width:200px;height:auto;">
<hr>
<font style="vertical-align: inherit;">
<font style="vertical-align: inherit;">Account: CapitainJack </font>
Xpath 最初使用但 id 更改:
//*[@id="popover784483"]/div[2]/font[1]/font
要使用的 Xpath:
//*[@class="popover fade right in"]/div[2]/font[1]/font
智慧大石
回首忆惘然
相关分类