onelfie page_login.py

from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import xlrd
import random
from base import BasePage

class LoginPage(BasePage):
# url = 'http://10.6.144.200/onelife'
url = 'http://10.6.144.43/onelife'
excelPath = './paremeters.xlsx'
workBook = xlrd.open_workbook(excelPath)
table = workBook.sheet_by_name('login')

for i in range(1, table.nrows):
colValues_0 = table.col_values(0)[i]
colValues_1 = table.col_values(1)[i]
colValues_2 = table.col_values(2)[i]
colValues_3 = table.col_values(3)[i]

exec('{} = colValues_1, colValues_2, colValues_3'.format(colValues_0))

def __init__(self, driver, url='http://10.6.144.200/onelife'):
self.driver = driver
self.url = url

def login(self):

self.driver.get(self.url)
self.driver.maximize_window()
self.driver.implicitly_wait(30)

# self.location(*self.username).send_keys('SG048')
self.input('SG048', *self.username)
self.input('cust@UAT20201024', *self.password)

# self.location(*self.password).send_keys('cust@UAT20201024')
ele = self.location(*self.language)
Select(ele).select_by_value('en_US')
sleep(2)

try:
driver.find_element_by_css_selector('div.sa-button-container > div > button').click()
sleep(2)
except:
pass

self.location(*self.button).click()
sleep(2)

try:
self.driver.find_element_by_class_name('confirm').click()
except:
pass
sleep(2)
self.driver.find_element_by_xpath('//a[@title="Settings"]/i').click()
ele = self.driver.find_element_by_xpath('//input[@id="switch-menu"]')
selected = ele.is_selected()
if selected:
ele.click()

if __name__ == '__main__':
driver = webdriver.Chrome()
page = LoginPage(driver)
page.login()

posted @ 2021-08-30 14:22  gupanpan  阅读(58)  评论(0)    收藏  举报