如何在python中访问具有相同类名的第二个元素

问题描述 投票:0回答:1

我在网页上有两个元素具有相同名称的类,我使用硒,我必须调用第二个元素,但我不能。我能怎么做?我尝试使用您阅读代码的firts类,但是它给了我这个错误:

Message: element click intercepted: Element <a class="navigate-target navigate-next"

第一个代码:

<a class="navigate-target navigate-prev no-outline" href="..." title="..." data-track="prevPhotoButtonClick" data-action="ad" style="height: 430px;">
<span class="hide-text">←</span>
</a>

第二代码(我需要什么:):

<a class="navigate-target navigate-next no-outline" href="..." title="..." data-track="nextPhotoButtonClick" data-action="ad" style="height: 430px;">
<span class="hide-text">→</span>
</a>
python-3.x
1个回答
0
投票

您应该使用:find_elements_by_class_name如此处引用:

https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.find_elements_by_class_name

然后在输出中获取列表的第二个元素。

© www.soinside.com 2019 - 2024. All rights reserved.