To print text … you have to induceWebDriverWait for the
visibility_of_element_located()and you can use either of the following
Locator Strategies:
Using
CSS_SELECtOR
, childNodes andstrip()
:print(driver.execute_script('return arguments[0].firstChild.textContent;', WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "a.call_recipe[href^='/recipes']")))).strip())Using
XPATH
,get_attribute()
andsplitlines()
:print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//a[@ and starts-with(@href, '/recipes')]"))).get_attribute("innerHTML").splitlines()[1])Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC



