UI自动化测试窗口切换、鼠标悬停、jenkins定时构建语法

一、 window

from selenium import webdriver
from selenium.webdriver.common.by import By
import  time
chrome = webdriver.Chrome()
# url='https://www.baidu.com/'
url='https://www.12306.cn/index/'
chrome.get(url)

# chrome.find_element(by=By.ID,value='kw').send_keys('12306官网')
# chrome.find_element(by=By.ID,value='su').submit()
#
# chrome.implicitly_wait(10)
#
# chrome.find_element('link text','中国铁路12306').click()

print(chrome.window_handles)
print('0===>',id(chrome.window_handles[0]))
# print('1===>',id(chrome.window_handles[1]))
chrome.switch_to.window(chrome.window_handles[-1])

#出发地
start=chrome.find_element("xpath",'//*[@id="fromStationText"]')
start.click()
chrome.find_element('xpath','//*[@id="ul_list1"]/li[32]').click()

#结束地址
end=chrome.find_element("xpath",'//*[@id="toStationText"]')
end.click()
chrome.find_element('xpath','//*[@id="ul_list1"]/li[9]').click()

#学生票
chrome.find_element('xpath','//*[@id="isStudentDan"]').click()

#查询
chrome.find_element('id','search_one').click()
default = chrome.current_window_handle
chrome.switch_to.window(chrome.window_handles[-1])
chrome.find_element('id','search-input').send_keys('北京')

time.sleep(2)

chrome.switch_to.window(default)
chrome.find_element('id','search-input').send_keys('长沙')

二、iframe

from selenium import webdriver
from time import sleep
chrome = webdriver.Chrome()
chrome.get('https://mail.qq.com/')
chrome.implicitly_wait(5)
# sleep(2)

# pth=chrome.find_element('xpath','/html/body/div/div[2]/div[2]/div[1]/div[1]/div[2]/div[2]/iframe')
# chrome.switch_to.frame(pth)

d=chrome.find_element('id','login_frame')
chrome.switch_to.frame(d)


chrome.find_element('xpath','//*[@id="u"]').send_keys('123')
# chrome.find_element('id','login_button').click()

sleep(2)
chrome.switch_to.default_content()
chrome.find_element('link text','帮助中心').click()

三、鼠标悬停

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

chrome = webdriver.Chrome()
chrome.get('https://www.baidu.com/')
chrome.maximize_window()

d=chrome.find_element('id','s-usersetting-top')

ActionChains(chrome).move_to_element(d).perform()
chrome.find_element('xpath','//*[@id="s-user-setting-menu"]/div/a[1]').click()
sleep(2)
chrome.find_element('xpath','//*[@id="se-setting-7"]/a[2]').click()
sleep(2)
chrome.switch_to.alert.accept()

sleep(2)
chrome.quit()

四、 jenkins定时构建语法

* * * * *
(五颗星,中间用空格隔开)
 
第一个*表示分钟,取值0~59
第二个*表示小时,取值0~23
第三个*表示一个月的第几天,取值1~31
第四个*表示第几月,取值1~12
第五个*表示一周中的第几天,取值0~7,其中0和7代表的都是周日

每天下午下班前18点定时构建一次
0 18 * * *

每天早上8点构建一次
0 8 * * *

每30分钟构建一次:
H/30 * * * *

每2个小时构建一次
H H/2 * * *

每天早上 81222点多个时间点进行构建
* 08,12,22 * * *

猜你喜欢

转载自blog.csdn.net/qq_44895262/article/details/126072308
今日推荐