Skip to main content
 首页 » 编程设计

python之Selenium Webdriver Python 查找下一个元素

2025年05月04日41davidwang456

我有这个 HTML 代码:

<caption> 
    <em id="qwerty"> ABC </em> 
</caption> 
 
<caption> 
    <em id="qwerty"> 123 </em> 
</caption> 

我如何使用 Selenium Webdriver 在 Python 中创建一个程序来找到 id="qwerty"的第二个元素?

请您参考如下方法:

您可以使用 find_elements_by_id()并取第二个元素(python 中的索引从 0 开始):

element = driver.find_elements_by_id('qwerty')[1]