I'm coding a script that set likes on instagram photos, but after some likes (once 14, once 50, once 64), the shell gives me this error:
in <module> ui.WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".dCJp8.afkep.coreSpriteHeartOpen._0mzm-"))).click() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) TimeoutException: Message:
I understand that the problem should be in webdriver wait,but I don't know how to improve my script.
this is my script:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome(executable_path = '/usr/local/bin/chromedriver')
driver.implicitly_wait(30)
driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
#log in
time.sleep(1)
usm = driver.find_element_by_name('username').send_keys("givcomomvrvglino")
pwd = driver.find_element_by_name('password').send_keys("x")
btnLog = driver.find_element_by_tag_name('form').submit()
#disattiva le notifiche
ui.WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,".aOOlW.HoLwm"))).click()
tag = "likeforfollow"
url_to_search = "https://www.instagram.com/explore/tags/" + tag + "/"
driver.get(url_to_search)
contatore = 0
for i in range(500):
if i == 0:
ui.WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".v1Nh3.kIKUG._bz0w"))).click()
ui.WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".dCJp8.afkep.coreSpriteHeartOpen._0mzm-"))).click()
ui.WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".HBoOv.coreSpriteRightPaginationArrow"))).click()
else:
ui.WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".dCJp8.afkep.coreSpriteHeartOpen._0mzm-"))).click()
ui.WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".HBoOv.coreSpriteRightPaginationArrow"))).click()
contatore = contatore + 1
print(contatore)
time.sleep(3)