如何在selenium中获取元素旁边的元素

时间:2017-12-26 14:19:02

标签: python selenium xpath css-selectors

我是python selenium的新手。

是否有可能获得总是存在于selenium中另一个元素旁边的元素?

说我希望.title.may-blank关闭https://www.reddit.com/并且总是在投票计数为div.midcol.unvoted > div.score.unvoted

theimage

我试试:

//*[contains(@class, "title may-blank ")]/following-sibling::div[@class='midcol unvoted']//*[contains(@class, 'unvoted')]

未检测到xpath

1 个答案:

答案 0 :(得分:0)

通过fowwowing Upvote CountCSS识别第一个 XPATH

  • CSS

    div#thing_t3_7m64jy > div.midcol.unvoted > div.score.unvoted
    
  • XPATH

    //div[@id='thing_t3_7m64jy']//div[@class='midcol unvoted']//div[@class='score unvoted']
    

通过以下News Item确定关于 Upvote Count 的第一个 XPATH

  • XPATH

    //div[@id='thing_t3_7m64jy']//div[@class='midcol unvoted']//div[@class='score unvoted']//following::a[2]