2

I have confirmed the xpath works using a Google Chrome plugin that tests xpaths. This is the xpath:

//meta[@property='og:url']/@content

and this is the line of code that works with other xpaths so I know the only variable is this current xpath:

pageID = get_data(driver,"//meta[@property='og:url']/@content")

But when I run my Python Selenium script I get the error:

"invalid selector" "it should be an element."

Am I only allowed to use xpaths that are visible? How can I select hidden elements that require view-page source?

NOTE: Thank you and my apologies if I am missing any information. This is my first post here and I only created a profile because I searched everywhere online and couldn't find a solution.

0

1 Answer 1

1

It is not clear from the question how the method get_data() is defined.

However, to extract the pageID you can use find_element_by_xpath() along with get_attribute() method as follows:

pageID = driver.find_element_by_xpath("//meta[@property='og:url']").get_attribute("content")
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the quick reply! I just tried that but got this mesage: AttributeError: 'str' object has no attribute 'get_attribute' Will keep experimenting and googling about this issue.

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.