In the above HTML, I would like to get the Value "INC3000...".
But if I use get_attribute() the value returned is None as it is rendered in JavaScript during runtime.
How can I get the value of "href=javascript:" (INC30000004609 (New))?
You need to use explicit wait for the result ready. JS rendered element cannot be obtained without waiting. Neither simple requests, nor selenium without waiting.
wait = WebDriverWait(driver, 10)
element = wait.until(element_has_text(By.XPATH, '//a[contains(@class, "btn")]'))
class element_has_text(object):
def __init__(self, locator, css_class):
self.locator = locator
def __call__(self, driver):
element = driver.find_element(*self.locator) # Finding the referenced element
if element.text:
return element
else:
return False
INC30000004609can be uniquely identified.