Python Forum

Full Version: Looping/Scheduling webelement select
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

I am wanting help with either turning this below code into either a For statement so I can ultimately create a loop for hourly or scheduling the below code to schedule it every hour:

from selenium import webdriver
from selenium import webdriver
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
import schedule
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.google.com/search?q=bing&source=lnms&tbm=nws&sa=X&ved=2ahUKEwjfy6yg0dnwAhWFvZ4KHV07BuQQ_AUoA3oECAEQBQ&biw=1036&bih=812&dpr=1.5")
button = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[7]/div/div[3]/div/div[1]/div/div[1]/div/div[4]")))
button.click()    
remove 2 of the 3 imports lines 1-3
you can use 'sched' ( https://docs.python.org/3/library/sched.html ) for scheduling,

or do it from OS command with cron (Linux), not sure what windows equivalent is.