How to find_element_by_link_text while having: NoSuchElement Exception?

前端 未结 4 1120
独厮守ぢ
独厮守ぢ 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 23:04

    It happened to me before that the find_element_by_link_text method sometimes works and sometimes doesn't work; even in a single case. I think it's not a reliable way to access elements; the best way is to use find_element_by_id.

    But in your case, as I visit the page, there is no id to help you. Still you can try find_elements_by_xpath in 3 ways:

    1- Accessing title: find_element_by_xpath["//a[contains(@title = 'T430')]"]

    2- Accessing text: find_element_by_xpath["//a[contains(text(), 'T430')]"]

    3- Accessing href: find_element_by_xpath["//a[contains(@href = 'http://www.thedostore.com/laptops/thinkpad-laptops/thinkpad-t430-u-black-627326q.html')]"].

    Hope it helps.

提交回复
热议问题