selenium自动化测试页面功能

from selenium import webdriver
from time import sleep
from selenium.webdriver.common.action_chains import ActionChains

# 加上参数,禁止 chromedriver 日志写屏
options = webdriver.ChromeOptions()
options.add_experimental_option(
    'excludeSwitches', ['enable-logging'])

driver = webdriver.Chrome(
    r'C:\Program Files\Google\Chrome\chromedriver.exe', 
    options=options  # 指定 options 参数
)

# driver = webdriver.Chrome(r'C:\Program Files\Google\Chrome\chromedriver.exe')
driver.get('https://booking-new.clounix.com/login')


# 输入登录名和密码,并点击登录
element = driver.find_element_by_xpath("/html/body/div/div/div/form/div[1]//input")
element.send_keys('yanghui2')

element = driver.find_element_by_xpath("/html/body/div/div/div/form/div[2]//input")
element.send_keys('123456')

element = driver.find_element_by_xpath("/html/body/div/div/div/form/div[3]//button").click()

# hold test
# hold free DUT
# elements = driver.find_elements_by_css_selector("#app .mid .left .el-table--fit  .el-table__body .el-table__row .el-button")
sleep(1)
trlist = driver.find_elements_by_css_selector("#app .mid .left .el-table--fit  .el-table__body .el-table__row .el-button")
print(len(trlist))

for row in trlist:
    row.click() 
    _item = driver.find_element_by_css_selector("#app > div > div.mid > div.left > div.el-overlay > div > div > div.el-dialog__body > div.el-select > div > div > span > span > i")
    ActionChains(driver).move_to_element(_item).click(element).perform()
    _hold = driver.find_element_by_xpath('//div[starts-with(@id,"el-popper")]/div[1]/div/div[1]/ul/li[1]')
    ActionChains(driver).move_to_element(_hold).click(element).perform()
    _confirm = driver.find_element_by_xpath('//*[@id="app"]/div/div[2]/div[1]/div[3]/div/div/div[2]/button')
    ActionChains(driver).move_to_element(_confirm).click(element).perform()
    # sleep(6)

# hold occupied DUT
for row in trlist:
    row.click() 
    _item = driver.find_element_by_css_selector("#app > div.mid > div.left > div.el-overlay > div > div > div.el-dialog__body > div.el-select > div > div > span > span > i > svg > path")
    ActionChains(driver).move_to_element(_item).click(element).perform()
    _hold = driver.find_element_by_xpath('//div[starts-with(@id,"el-popper")]/div[1]/div/div[1]/ul/li[1]')
    ActionChains(driver).move_to_element(_hold).click(element).perform()
    _confirm = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[3]/div/div/div[2]/button/span')
    ActionChains(driver).move_to_element(_confirm).click(element).perform()
    # sleep(6)

# hold DUT always but not using
_longDUT = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[2]/div[3]/table/tbody/tr[8]/td[5]/div/div/button').click()
_item =  driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[3]/div/div/div[2]/div[1]/div/div/span/span/i')
ActionChains(driver).move_to_element(_item).click(element).perform()
_4hour = driver.find_element_by_xpath('//div[starts-with(@id,"el-popper")]/div[1]/div/div[1]/ul/li[8]')
ActionChains(driver).move_to_element(_4hour).click(element).perform()
_confirm = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[3]/div/div/div[2]/button/span')
ActionChains(driver).move_to_element(_confirm).click(element).perform()

# trigger booking
driver2 = webdriver.Chrome(r'C:\Program Files\Google\Chrome\chromedriver.exe')
driver2.get('https://booking-new.clounix.com/login')

element = driver2.find_element_by_xpath("/html/body/div/div/div/form/div[1]//input")
element.send_keys('yanghui')

element = driver2.find_element_by_xpath("/html/body/div/div/div/form/div[2]//input")
element.send_keys('123456')

element = driver2.find_element_by_xpath("/html/body/div/div/div/form/div[3]//button").click()
_longDUT = driver2.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[2]/div[3]/table/tbody/tr[8]/td[5]/div/div/button').click()
_item =  driver2.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[3]/div/div/div[2]/div[1]/div/div/span/span/i')
ActionChains(driver2).move_to_element(_item).click(element).perform()
_4hour = driver2.find_element_by_xpath('//div[starts-with(@id,"el-popper")]/div[1]/div/div[1]/ul/li[8]')
ActionChains(driver2).move_to_element(_4hour).click(element).perform()
_confirm = driver2.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[3]/div/div/div[2]/button/span')
ActionChains(driver2).move_to_element(_confirm).click(element).perform()

# release booking DUT
row = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[2]/div[3]/table/tbody/tr/td[5]/div/div/button[2]')
row.click()
_release = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[2]/div[3]/table/tbody/tr/td[5]/div/div/button[2]')
ActionChains(driver).move_to_element(_release).click(element).perform()
_ok = driver.find_element_by_xpath("/html/body/div/div/div[3]/button").click()

# release all occupied DUT
res_trlist = driver.find_elements_by_xpath('//*[@id="app"]/div[2]/div[1]/div[2]/div[3]/table/tbody/tr')
print(len(res_trlist))

for row in res_trlist:
    row = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[2]/div[3]/table/tbody/tr/td[5]/div/div/button[2]')
    row.click()
    _release = driver.find_element_by_xpath('//*[@id="app"]/div[2]/div[1]/div[2]/div[3]/table/tbody/tr/td[5]/div/div/button[2]')
    ActionChains(driver).move_to_element(_release).click(element).perform()
    _ok = driver.find_element_by_xpath("/html/body/div/div/div[3]/button").click()
    sleep(9)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

洋气月

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值