0

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&amp;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&amp;av=200007162833925">104</span>
  </span>
  <span class="_4arz">
    <span data-hover="tooltip" data-tooltip-uri="/ufi/reaction/tooltip/?ft_ent_identifier=2411812215520941&amp;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?

1
  • There are 2 same span nodes with text "104"... Is it typo? Commented Feb 8, 2018 at 9:09

1 Answer 1

2

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"]]

...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.