在Selenium,Python中找到下一个同级元素? [英] Find next sibling element in Selenium, Python?

查看:782
本文介绍了在Selenium,Python中找到下一个同级元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个HTML:

<body>
    <p id='one'> 1A </p>
    <p id='two'> 2A </p>
    <p id='three'> 3A </p>
    <p id='four'> 4A </p>
    <p id='five'> 5A </p>
    <p id='six'> 6A </p>
    <p id='seven'> 7A </p>
</body>

我使用下面的代码来获取第一个p标记元素:

I use the code below to get the first p tag element:

elem = driver.find_element_by_id('one')

现在,如何找到elem的下一个兄弟姐妹?

Now, how to find the next sibling of elem?

推荐答案

我想更正Mark Rowlands的答案.正确的语法将是

I want to correct Mark Rowlands's answer,. The correct syntax will be

driver.find_element_by_xpath("//p[@id='one']/following-sibling::p")

这篇关于在Selenium,Python中找到下一个同级元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆