I have this script that goes to google takeout and downloads the takeout file. The issue I am having is, some accounts require a relogin when the "Takeout_dlbtn" is clicked and others can download directly. I tried to put this IF ELSE statement. Where if "password" is displayed, we run through the steps to re-enter password and then download. And if the "password" does not appear, we assume we do not need to login and can download right away.
The issue I am having is, my IF statement runs, and if the password page is shown, it will enter password and then download. But if the password page is not shown, the IF statement is still run and my ELSE statement does not get executed. It throws this error "no such element :Unable to locate element: {"Method":" css select","selector":"[name-"password"]"}"
How do I get the ELSE function to run if the "password" element is not shown? Any help would be appreciated.
def DLTakeout(self, email, password):
self.driver.get("https://takeout.google.com/")
time.sleep(2)
self.driver.find_element_by_xpath(takeout_DLbtn).click()
time.sleep(4)
if self.driver.find_element_by_name("password").is_displayed():
print("IF statement")
time.sleep(3)
self.driver.find_element_by_name("password").clear()
time.sleep(5)
self.driver.find_element_by_name("password").send_keys(password)
time.sleep(5)
self.driver.find_element_by_xpath("//*[@id='passwordNext']/div/button/div[2]").click()
print("Downloading")
logging.info("Downloading")
time.sleep(10) #change time.sleep to a higher number when download file is in gbs #1500
self.write_yaml(email)
print("Write to yaml successfully")
logging.info("Write to yaml successfully")
print("Zip move process about to start")
logging.info("Zip move process about to start")
time.sleep(4)
else:
print("else statement")
time.sleep(5)
print("Downloading")
logging.info("Downloading")