Is there a way to search the “data-ftjson” of an HTML element using Selenium for Python?
I am trying to find a button on a website that will change based on the date. The button will always have the "newreq = yes" identifier present in the "data-ftjson" portion of its element. I need a way to check for this element and then click the button. The screenshot below shows the HTML element of said button. I am using the Selenium WebDriver in Python. Any help would be greatly appreciated.
add the class name of your "a" element. In order to get an attribute value, you can use the method "get_attribute("element_name")
linkElement = driver.find_element_by_xpath("//a[contains(@class,'THE CLASS NAME')]") attributeValue = linkElement.get_attribute("data-ftjson") stringElement = "\"newreq\":\"yes\"" if (stringElement in attributeValue): #do something else: #do something #or by json for this you need to import json jsonValue = attributeValue['newreq'] if jsonValue == 'yes': #do something else: #do something