What is the process to get data-href instead of href with selenium in python?

244    Asked by AndreaBailey in Cyber Security , Asked on Apr 21, 2022

I currently have a python code that should grab a link from google. However, google uses a somewhat different method to linking. how could I grab the data-href instead of just href. this is the html example of a google link, the code is different when I use firefox.. there is no data-href:

Answered by Andrea Bailey

Data-href is an attribute of a HTML tag, try to use get_attribute method, something like: url = browser.find_element_by_xpath("//a").get_attribute("data-href") For more information see: http://selenium-python.readthedocs.org/en/latest/api.html#selenium.webdriver.remote.webelement.WebElement.get_attribute Or this for examples: https://stackoverflow.com/questions/12579061/python-selenium-find-object-attributes-using-xpath



Your Answer

Interviews

Parent Categories