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.

jackson
  • 35
  • 4

1 Answers1

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")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 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. – jackson Dec 12 '18 at 08:31