Selenium / lxml : Get xpath
问题 Is there a get_xpath method or a way to accomplish something similar in selenium or lxml.html. I have a feeling that I have seen somewhere but can't find anything like that in the docs. Pseudocode to illustrate: browser.find_element_by_name('search[1]').get_xpath() >>> '//*[@id="langsAndSearch"]/div[1]/form/input[1]' 回答1: As there is no unique mapping between an element and an xpath expression, a general solution is not possible. But if you know something about your xml/html, it might be easy