I want to iterate through certain elements and then click them. In the process, I was suggested to utilize Selenium's WebDriverWait, but I am facing some difficulties which after trying for a while, have not yet been able to figure out.
My code:
# finds all heart elements
hearts = driver.find_elements_by_xpath("//span[@class='fr66n']")
for h in range(len(hearts)):
try:
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, hearts[h])));
ActionChains(driver).move_to_element(hearts[h]).click(hearts[h]).perform()
counter += 1
print(str(counter) + "/" + str(len(hearts)))
except exceptions.StaleElementReferenceException as e:
raise e
Error encountered:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'value' must be a string
It points to this line:
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, hearts[h])));
By guess, I assume it refers that hearts[h] should be a String, but isn't it already? Hopefully my interpretation is wrong and someone has a better idea. Thanks.