If you take a look at this site, you will see the title/text "Example Domain". Is it possible to get its xpath which is /html/body/div/h1 using selenium? Is there any other possibilities? I mean I want to get xpath itself and not its content!
I know we can get the page_soruce using driver.page_source but this not what I'm looking for. I simply expect an output as /html/body/div/h1.
I tried this:
test = driver.page_source
ps = str(test)
root = etree.fromstring(ps)
tree = etree.ElementTree(root)
find_text = etree.XPath("//p[text()='my_target_text']") # in our case Example Domain
for target in find_text(root):
print(tree.getpath(target))
It returns:
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch