Created
September 10, 2020 03:22
-
-
Save dev4Fun/fc5cd948097dd2b6a50f2b3f7f6e1451 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # additional imports | |
| import logging | |
| import config | |
| from selenium.common.exceptions import NoSuchElementException, TimeoutException | |
| from selenium.webdriver.common.by import By | |
| from selenium.webdriver.support import expected_conditions as ec | |
| logger = logging.getLogger() | |
| ... | |
| def log_in(self): | |
| self.driver.get("https://www.instagram.com/") | |
| try: | |
| self.wait_until(ec.presence_of_element_located((By.NAME, 'username'))) | |
| try: | |
| self.driver.find_element_by_name('username').send_keys(config.USERNAME) | |
| self.driver.find_element_by_name('password').send_keys(config.PASSWORD) | |
| self.driver.find_element_by_xpath( | |
| '//*[@id="react-root"]/section/main/article/div[2]/div[1]/div/form/div[4]/button').click() | |
| except NoSuchElementException as e: | |
| logger.warning(f"Could not find element. Error: {e}") | |
| return | |
| except TimeoutException: | |
| pass | |
| try: | |
| # remember this browser prompt | |
| self.driver.find_element_by_xpath( | |
| '//*[@id="react-root"]/section/main/div/div/div/section/div/button').click() | |
| except NoSuchElementException: | |
| pass | |
| try: | |
| # turn on notifications prompt | |
| self.driver.find_element_by_xpath("/html/body/div[4]/div/div/div/div[3]/button[2]").click() | |
| logger.debug("Skipping turn on notifications") | |
| except NoSuchElementException: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment