From ea69a29e04648ab7784ed63adf7e19604c2f229f Mon Sep 17 00:00:00 2001 From: EmaMaker Date: Fri, 12 Feb 2021 12:41:33 +0100 Subject: [PATCH] prevent crash when trying to hang up the call --- browser_manager.py | 52 +++++++--------------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/browser_manager.py b/browser_manager.py index 74a95e3..89e0a31 100644 --- a/browser_manager.py +++ b/browser_manager.py @@ -13,13 +13,9 @@ from selenium.webdriver.common.keys import Keys from selenium.common.exceptions import NoSuchElementException import time as t +from utils import * -G_ACCOUNT_MAIL = None -G_ACCOUNT_PASS = None - -FIREFOX_DVD_DIR = "/usr/bin/geckodriver" - '''Locating by xpath here is the best thing to do here, since google Meet changes selectors, classes name and all that sort of stuff for every meeting XPaths remaing the same, but a slight change by them would make this program fail. The xpath is found clicking by inspecting the element of the searched button, and finding the parent div tthat has role="button" tag @@ -43,14 +39,9 @@ CHAT_CLOSE_BTN_XPATH = '/html/body/div[1]/c-wiz/div[1]/div/div[6]/div[3]/div[3]/ browser = None def initFirefox(): - global browser, G_ACCOUNT_MAIL, G_ACCOUNT_PASS + global browser - print("Input your google account credentials. The information will not be stored anywhere and you will have to relogin everytime you restart this bot\n") - G_ACCOUNT_MAIL = input("Type your email: ") - G_ACCOUNT_PASS = input("Type your password: ") - - #webdriver.FirefoxProfile('/home/emamaker/Documents/Projects/GoogleMeetBot/firefox_profile') - browser = webdriver.Firefox() + browser = webdriver.Firefox(firefox_profile=webdriver.FirefoxProfile(FIREFOX_PROFILE), executable_path=FIREFOX_DVD_DIR) def joinMeeting(link): global browser @@ -102,36 +93,9 @@ def checkStarted(): return False return True -def loginIntoGoogle(): - global browser - browser.get("https://myaccount.google.com/?utm_source=sign_in_no_continue") - t.sleep(3) - #we can use selectors in this webside, since they're static - #login button - clickButton(By.CSS_SELECTOR, "li.h-c-header__cta-li:nth-child(2) > a:nth-child(1)") - #login with google - #clickButton(By.CSS_SELECTOR, "button.s-btn__icon:nth-child(1)") - #write email - writeText(By.CSS_SELECTOR, "#identifierId", G_ACCOUNT_MAIL) - t.sleep(3) - #write pwd - writeText(By.XPATH, "/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div[1]/div/div/div/div/div[1]/div/div[1]/input", G_ACCOUNT_PASS) - t.sleep(3) - -def loginIntoGoogleWithStackOverflow(): - global browser - browser.get("https://stackoverflow.com/users/login?ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f") - t.sleep(3) - #we can use selectors in this webside, since they're static - #login with google - clickButton(By.CSS_SELECTOR, "#openid-buttons > button.grid--cell.s-btn.s-btn__icon.s-btn__google.bar-md.ba.bc-black-100") - #login button - #write email - writeText(By.CSS_SELECTOR, "#identifierId", G_ACCOUNT_MAIL) - t.sleep(3) - #write pwd - writeText(By.XPATH, "/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[1]/div/form/span/section/div/div/div[1]/div[1]/div/div/div/div/div[1]/div/div[1]/input", G_ACCOUNT_PASS) - t.sleep(3) - def hangUpMeeting(): - clickButton(By.XPATH, HANG_UP_BTN_XPATH) + try: + clickButton(By.XPATH, HANG_UP_BTN_XPATH) + except: + return False + return True