Hi,
from selenium import webdriver def Login_reddit(): Email = driver.find_element_by_xpath('//div[@class="form_column"]/input[2]') Email.send_keys(username) time.sleep(1) Password = driver.find_element_by_xpath('//div[@class="form_inputs"]/div[2]/input[1]') Password.send_keys(password) print("Email and Password successfully entered") #Login = driver.find_element_by_xpath('//div[@class="form_inputs"]/div[3]/input[1]') time.sleep(5) wait1 = WebDriverWait(driver, 11) Login = wait1.until(ec.element_to_be_clickable((By.XPATH, "//div[@class='form_inputs']/div[2]/input[1]"))) ActionChains(driver).move_to_element(Login).perform() time.sleep(3) Login.click() print("logged in successfully") def Add_question(): #AddQuestion = driver.find_element_by_xpath('//div[@class="right_contents"]/div[3]/a') time.sleep(4) wait6 = WebDriverWait(driver, 12) AddQuestion = wait6.until(ec.element_to_be_clickable((By.XPATH, "//div[@class='right_contents']/div[3]/a"))) AddQuestion.click() time.sleep(6) #question = input("Enter your question:") #Type in the question #TypeQuestion = driver.find_element_by_xpath('//div[@class="modal_wrapper normal"]/div[1]/div[@class="modal_content modal_content_tabs"]/div[1]/div[3]/div[1]/textarea[@class="selector_input text"]') wait3 = WebDriverWait(driver, 10) TypeQuestion = wait3.until(ec.visibility_of_element_located((By.XPATH, '//div[@class="modal_wrapper normal"]/div[1]/div[@class="modal_content modal_content_tabs"]/div[1]/div[2]/div[1]/textarea[@class="selector_input text"]'))) TypeQuestion.send_keys(line.strip()) time.sleep(7) #Click add question #AddQuestion = driver.find_element_by_xpath('//div[@class="modal_wrapper normal"]/div[1]/div[@class="modal_footer"]/div[@class="modal_actions"]/span[2]/a') wait4 = WebDriverWait(driver, 10) AddQuestion = wait4.until(ec.visibility_of_element_located((By.XPATH, "//div[@class='modal_wrapper normal']/div[1]/div[@class='modal_footer']/div[@class='modal_actions']/span[3]/a"))) AddQuestion.click() time.sleep(11) #Click on confirm #Confirm = driver.find_element_by_xpath('//div[@class="modal_overlay"]/div[3]/div[1]/div[@class="modal_footer"]/div[@class="modal_actions"]/a') #wait = WebDriverWait(driver, 10) #Confirm = wait.until(ec.visibility_of_element_located((By.XPATH, "//div[@class='modal_overlay']/div[2]/div[1]/div[@class='modal_footer']/div[@class='modal_actions']/a"))) #Confirm.click() #time.sleep(2) wait8 = WebDriverWait(driver, 10) Loader = wait8.until(ec.invisibility_of_element_located((By.XPATH, "//div[@class='multimodal_loading_overlay']"))) wait5 = WebDriverWait(driver, 10) Cancel = wait5.until(ec.element_to_be_clickable((By.XPATH, "//div[@class='modal_overlay']/div[2]/div[1]/div[@class='modal_footer']/div[@class='modal_actions']/span[2]/a"))) #Cancel = driver.find_element_by_xpath("//div[@class='modal_overlay']/div[2]/div[1]/div[@class='modal_footer']/div[@class='modal_actions']/span[1]/a") Cancel.click() #Alert Box obj = driver.switch_to.alert obj.accept() time.sleep(3) start = time.time() options = Options() Headless = input("Do you want to go headless?") if Headless == "y": options.headless = True driver = webdriver.Firefox(options=options) else: options.headless = False driver = webdriver.Firefox(options=options) #open reddit driver.get("https://www.reddit.com") Login_reddit() driver.get("https://www.reddit.com") with open('questions.txt') as f: try: for lin in f: Add_question() print ("successfully added " + line) except: print("failed until" + line) driver.quit() end = time.time() hours, rem = divmod(end-start, 3600) minutes, seconds = divmod(rem, 60) print("{:0>2}:{:0>2}:{:05.2f}".format(int(hours),int(minutes),seconds))