Skip to content

Instantly share code, notes, and snippets.

@sulianov
Last active May 3, 2019 19:22
Show Gist options
  • Save sulianov/25a6795fb7969d89136e6d2f3e552e31 to your computer and use it in GitHub Desktop.
Save sulianov/25a6795fb7969d89136e6d2f3e552e31 to your computer and use it in GitHub Desktop.
Logout from all screens (v.4)
"""
In order to avoid register device screen this needs to be run under Google Account in the browser where particular user is registered (see options of webdriver).
Logout from:
Disclaimer
Dashboard
Deposits
Checking details
CD details
Loans
Loan details
Transaction History
Transaction History - expanded filter tool
Transfers
Transfers - One-time details
Transfers - Recurring details
Stop Payment
Statements
Messages - Inbox
Messages - Outbox
Messages - Compose
Settings
Settings - Show Contacts
Settings - Manage Alerts
Settings - Manage Alerts - Alert details
Settings - Change Password
Settings - Change Username
Settings - Registered Devices
Settings - Registered Devices - Details
Settings - Card Management
"""
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from colorama import Fore
from colorama import Style
import time
options = webdriver.ChromeOptions()
options.add_argument(r"--user-data-dir=C:\Users\domes\AppData\Local\Google\Chrome\User Data")
options.add_argument("--start-maximized")
driver = webdriver.Chrome(chrome_options=options)
driver.implicitly_wait(4)
url = ''
username = ''
psw = 'Password1'
dashboardxpaths = ['//*[@id="mainWrapper"]/div/div[3]/div/div[1]/div/div/div[2]/div[1]', '//*[@id="mainWrapper"]/div/div[3]/div/div[2]/div/div/div[2]/div', '//*[@id="mainWrapper"]/div/div[3]/div/div[3]/div/div/div[2]/div']
#order: [accounts, cd, loans]
transfersxpath = ['//*[@id="mainWrapper"]/div/div[3]/div/div[1]/div[2]/table/tbody/tr[1]', '//*[@id="mainWrapper"]/div/div[3]/div/div[2]/div[2]/table/tbody/tr']
#order: [recurring, one-time]
accounts = '/web/accounts'
settings = '/web/settings'
ahrefslinks = ['/web/deposits', '/web/loans', '/web/transactions', '/web/transfers', '/web/checks/stop-payment', '/web/statements']
ahrefssettings = ['/contacts', '/alerts', '/change-password', '/change-username', '/registered-devices', '/cards/no-cards']
def openloginaccept(url, username, psw, disstate='0'):
#open url
driver.get(url)
time.sleep(1)
#log in
ln = driver.find_element_by_id('loginname')
ln.send_keys(Keys.CONTROL + "a")
ln.send_keys(username)
pw = driver.find_element_by_id('password')
pw.send_keys(Keys.CONTROL + "a")
pw.send_keys(psw)
driver.find_element_by_name('logIn').click()
print('"%s" is logged in' % username)
time.sleep(2)
#accept disclaimer
if disstate == '0':
driver.find_element_by_xpath('//*[@id="modal-disclaimer"]/div/div/div[2]/div/div/div[11]/button[2]').click()
print('Disclaimer is accepted')
time.sleep(2)
else:
pass
def logout():
driver.find_element_by_name('logout').click()
time.sleep(1)
def verify():
text = driver.find_element_by_xpath('//*[@id="mainWrapper"]/div/div[3]/div/div[1]')
btnlogout = driver.find_element_by_name('btn-logout')
if text.is_displayed() and \
btnlogout.is_displayed():
print('"%s" text is displayed.' % text.text)
print('"%s" button is displayed.' % btnlogout.text)
print('------')
return
def tryverify():
try:
verify()
except NoSuchElementException:
print(
f"{Fore.RED}FAILED{Style.RESET_ALL}:'{NoSuchElementException}': Logout page is not complete.")
print('From URL: %s ' % driver.current_url)
driver.save_screenshot('Screenshots-logout/failed')
print('------------------------------------------------------------------------------')
pass
def clickat(toplink='dummytopitem', sublink='dummysubitem', cssselector='dummyclass', xpath='dummyxpath', clickelement='dummyelement'):
if toplink == 'dummytopitem':
pass
else:
driver.find_element_by_xpath('//a[@href="' + toplink + '"]').click()
print("%s is clicked" % toplink)
if sublink == 'dummysubitem':
pass
else:
driver.find_element_by_xpath('//a[@href="'+sublink+'"]').click()
print(f"{Fore.GREEN}%s{Style.RESET_ALL} is clicked" % sublink)
if cssselector == 'dummyclass':
pass
else:
driver.find_element_by_css_selector(cssselector).click()
print(f"{Fore.GREEN}%s{Style.RESET_ALL} is clicked" % cssselector)
if xpath == 'dummyxpath':
pass
else:
driver.find_element_by_xpath(xpath).click()
if clickelement == 'dummyelement':
pass
else:
driver.find_element_by_xpath('//a[@href="' + clickelement + '"]').click()
time.sleep(1)
def gototransfers(ahref):
driver.find_element_by_xpath('//a[@href="' + ahref + '"]').click()
openloginaccept(url, username, psw, '1')
clickat(xpath='//*[@id="modal-disclaimer"]/div/div/div[2]/div/div/div[11]/button[1]')
tryverify()
"""
openloginaccept(url, username, psw)
logout()
print('User is logged out from the Dashboard')
tryverify()
for ahref in ahrefslinks:
openloginaccept(url, username, psw)
clickat(accounts, ahref)
logout()
tryverify()
openloginaccept(url, username, psw)
clickat(sublink='/web/messages/inbox')
logout()
tryverify()
openloginaccept(url, username, psw)
clickat('/web/messages/inbox', '/web/messages/outbox')
logout()
tryverify()
openloginaccept(url, username, psw)
clickat('/web/messages/inbox', cssselector='#mainWrapper > div > div.main-layout__Content-crtJMu.bfkUWT > div > div.widget__WidgetContent-gfqflg.cjMROP > div > div.messages-main-panel__MainPanel-fEXWiC.cZdoCT.flex__Flex-ljbqlG.lbuNrg > div > button')
logout()
tryverify()
openloginaccept(url, username, psw)
clickat('/web/settings')
logout()
tryverify()
for ahref in ahrefssettings:
openloginaccept(url, username, psw)
clickat(settings, ahref)
logout()
tryverify()
for path in dashboardxpaths:
openloginaccept(url, username, psw)
clickat(xpath=path)
logout()
tryverify()
for path in transfersxpath:
openloginaccept(url, username, psw)
gototransfers('/web/transfers')
clickat(xpath=path)
logout()
tryverify()
openloginaccept(url, username, psw)
clickat('/web/transfers', '/transfers/new')
logout()
tryverify()
openloginaccept(url, username, psw)
clickat('/web/settings', '/alerts', clickelement='/web/settings/alerts/balance/create')
logout()
tryverify()
openloginaccept(url, username, psw)
clickat('/web/settings', '/registered-devices', xpath='//*[@id="mainWrapper"]/div/div[3]/div/div[2]/div/div[2]/table/tbody/tr[1]')
logout()
tryverify()
openloginaccept(url, username, psw)
clickat('/web/accounts', '/web/transactions', clickelement='#')
logout()
tryverify()
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment