Can someone please show me hot to run login() only once inside this Loop? Firts time it will open https://mywebsite.com/1234 and ask for a login, login() will do this, then it will go and download .xlsx files. Then it will go to https://mywebsite.com/4567 and login() will try to do it's job again, but there's no need. So il will set an error as, it can't find username field.
Is there any way so login would run only 1st time ?
Help please!
web_link='https://mywebsite.com/'
tt_nr=TT_usrinput.get(0.1, END)
wait = WebDriverWait(self,10)
t=tt_nr.split('\n')
for i in t:
if i != "":
fin=web_link+i
self.maximize_window()
self.delete_all_cookies()
self.get(fin)
login()
WebDriverWait(self, 30).until(EC.element_to_be_clickable((By.ID, 'tab_related_items'))) # click Related Items
self.find_element_by_id('tab_related_items').click()
WebDriverWait(self, 5).until(
EC.element_to_be_clickable((By.XPATH, '//a[@target="_blank" and contains(@href, ".xlsx")]')))
elemsxlsx = self.find_element_by_xpath('//a[@target="_blank" and contains(@href, ".xlsx")]')
elemsxlsx.click()