Reputation: 4291
I want to click a link using Selenium with Python. The text is "104" in the following html code:
<a class="_2x4v" href="/ufi/reaction/profile/browser/?ft_ent_identifier=2411812215520941&av=200007162833925" rel="ignore" role="button">1045
<span aria-hidden="true" class="_1g5v">
<span data-hover="tooltip" data-tooltip-uri="/ufi/reaction/tooltip/?ft_ent_identifier=2411812215520941&av=200007162833925">104</span>
</span>
<span class="_4arz">
<span data-hover="tooltip" data-tooltip-uri="/ufi/reaction/tooltip/?ft_ent_identifier=2411812215520941&av=200007162833925">104</span>
</span>
</a>
I tried
driver.find_element_by_xpath('//a[text()="104"]').click()
But I received an error:
no such element: Unable to locate element: {"method":"xpath","selector":"//a[text()="104"]"}
What should I do?
Upvotes: 0
Views: 98
Reputation: 52665
Link has no child text node "104"
- it's child text node of span. You can try below options to match required link:
//a[span="104"]
or
//a[.//text()="104"]
or
//a[.//span[text()="104"]]
...
Upvotes: 2