How to find_element_by_link_text while having: NoSuchElement Exception?

前端 未结 4 1151
独厮守ぢ
独厮守ぢ 2021-01-14 22:31

This question has been asked over and over again - and in-spite of trying all the hacks I still can\'t seem to figure out what\'s wrong.

I tried increasing t

4条回答
  •  情歌与酒
    2021-01-14 22:48

    From viewing the source of the page that you provided a link to, it seems you are using an incorrect selector.

    You should use instead find_elements_by_link_text(u'text here')[0] to select the first occurrence instead as there seems to be the potential for multiple links with the same link text.

    So instead of:

    self.assertEqual("Thinkpad Edge E530 (Black)", driver.find_element_by_link_text("Thinkpad Edge E530 (Black)").text)
    

    You should use:

    self.assertEqual("Thinkpad Edge E530 (Black)", driver.find_elements_by_link_text("Thinkpad Edge E530 (Black)")[0].text)
    

提交回复
热议问题