Skip to content

Instantly share code, notes, and snippets.

@sulianov
Last active May 3, 2019 19:22
Show Gist options
  • Save sulianov/13266ce3edb17cf26dd0a37c6c594a41 to your computer and use it in GitHub Desktop.
Save sulianov/13266ce3edb17cf26dd0a37c6c594a41 to your computer and use it in GitHub Desktop.
"""
Check for text equivalents on the Login page, SMS Code page, Password Reset page, Password Reset Success screen.
"""
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 = ''
username2 = ''
psw = 'Password1'
driver.get(url)
time.sleep(1)
olb = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.irNclb > h1')
usernamefield = driver.find_element_by_xpath('//*[@id="app"]/div/div[2]/div/div[2]/form/div[1]/label')
pswfield = driver.find_element_by_xpath('//*[@id="app"]/div/div[2]/div/div[2]/form/div[2]/label')
forpsw = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div.flex__Flex-ljbqlG.gwdZCX > a')
submit = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div.flex__Flex-ljbqlG.gwdZCX > div > button')
fieldslogin = [olb, usernamefield, pswfield, forpsw, submit]
def inputcredentials(username, password):
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)
def checkfortext(field):
if field.text:
print('Field has text equivalent. It is "%s".' % field.text)
else:
print(f'{Fore.RED}The field does not have equivalent. Selector is: "%s"{Style.RESET_ALL}' % field)
print('------------------------------------------------')
for field in fieldslogin:
checkfortext(field)
time.sleep(1)
inputcredentials(username2, psw)
olb = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.irNclb > h1')
text1 = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > h4:nth-child(1)')
text2 = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > h4:nth-child(2)')
text3 = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div.field__Wrapper-dGmno.ieHrSd > label')
smsresend = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > h4:nth-child(1)')
smssubmit = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div.flex__Flex-ljbqlG.eOeNHn > button.button__Button-hQMOnA.gmtuOz')
fieldssms = [olb, text1, text2, text3, smsresend, smssubmit]
print('------------------------------------------------')
for field in fieldssms:
checkfortext(field)
driver.get(url)
driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div.flex__Flex-ljbqlG.gwdZCX > a').click()
forgotpswheader = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.irNclb > h1')
forgotusername = driver.find_element_by_xpath('//*[@id="app"]/div/div[2]/div/div[2]/form/div[1]/label')
forgotlastname = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div:nth-child(2) > label')
forgotphone = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div:nth-child(3) > label')
forgotemail = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div:nth-child(4) > label')
forgotsubmit = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > form > div.flex__Flex-ljbqlG.gwdZCX > div > button')
fieldsforgot = [forgotpswheader, forgotusername, forgotlastname, forgotphone, forgotemail, forgotsubmit]
print('------------------------------------------------')
for field in fieldsforgot:
checkfortext(field)
usernameinput = driver.find_element_by_css_selector('#loginName')
usernameinput.send_keys('test')
lastnameinput = driver.find_element_by_css_selector('#lastName')
lastnameinput.send_keys('test')
phoneinput = driver.find_element_by_css_selector('#phoneNumber')
phoneinput.send_keys('2222222222')
emailinput = driver.find_element_by_css_selector('#email')
emailinput.send_keys('[email protected]')
forgotsubmit.click()
forgotpswheader = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.irNclb > h1')
text4 = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > div > p:nth-child(1)')
text5 = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > div > p:nth-child(2)')
text6 = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > div > div > div')
gotologin = driver.find_element_by_css_selector('#app > div > div.login-layout__Wrapper-bcwZpm.iHGxAN > div > div.flex__Flex-ljbqlG.TRUMZ > div > div > button')
forgotsuccessfields = [forgotpswheader, text4, text5, text6, gotologin]
print('------------------------------------------------')
for field in forgotsuccessfields:
checkfortext(field)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment