0

I am trying to get the URL ('href') of the below element in Python with Selenium. For the life of me it is not working, this is the only output I get is as an example:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="href"]"}

This is the element I want to get the ('Href') or ('Text') from:

code.private.pri

Selector: #tinymce > p:nth-child(20) > a

Xpath: //*[@id="tinymce"]/p[7]/a

Full Xpath: /html/body/p[7]/a

I tried the following methods to find the element on the page with no luck:

Selector Xpath Full Xpath

Only get: NoSuchElementException: Message: no such element: Unable to locate element:

1

1 Answer 1

0

You have to use 'get_attribute()' function to get the urls:

For example, if this XPath is correct - '//*[@id="tinymce"]/p[7]/a', then locator should be like this:

driver.fine_element(By.XPATH, "//*[@id='tinymce']/p[7]/a").get_attribute("href")
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the response, tried you suggestion but unfortunately, it's also not working: NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='tinymce']/p[7]/a"}
Your locator is wrong, use the correct locator.

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.