lab_top.py
1.安装python3,版本3.10.5,选择添加变量
2.安装vcode,版本1.69.0
3.安装chromedrive,下载地址:https://sites.google.com/chromium.org/driver/,一定要和浏览器版本对应
4.在vscode中安装:pip install selenium
5.D:\chromedriver_win32\chromedriver.exe
from doctest import master from logging import root from msilib.schema import MsiAssembly, MsiAssemblyName from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time PATH = "D:\chromedriver_win32\chromedriver.exe" driver = webdriver.Chrome(PATH) driver.get("https://lab.yaozh.com") #打开lab.yaozh.com search = driver.find_element("name","user[login]") search.send_keys("root") search = driver.find_element("name","user[password]") search.send_keys("988527lyp0...") search.send_keys(Keys.RETURN) #输入用户名密码并登录 time.sleep(1) driver.get("https://lab.yaozh.com/yaozh/top/branches/new") #等待两秒,备份master分支 driver.find_element(By.XPATH,"//*[@id='new-branch-form']/div[2]/div/div[1]/button/div").click() mas = driver.find_element(By.XPATH,"//*[@id='new-branch-form']/div[2]/div/div[1]/div/div[2]/input") mas.send_keys("master") time.sleep(1) mas.send_keys(Keys.RETURN) time.sleep(1) now = time.strftime("%m%d_%H%M") search = driver.find_element(By.XPATH,"//*[@id='branch_name']") search.send_keys("top",now) search.send_keys(Keys.RETURN) #输入备份的master的名字 WebDriverWait(driver,3).until( EC.presence_of_element_located((By.XPATH, "//*[@id='tree-slider']/thead/tr/th[1]")) ) driver.get("https://lab.yaozh.com/yaozh/top/merge_requests/new") time.sleep(1) driver.find_element(By.XPATH,"//*[@id='new_merge_request']/div[2]/div[1]/div/div[2]/div[2]/button").click() time.sleep(1) search = driver.find_element(By.XPATH,"//*[@id='new_merge_request']/div[2]/div[1]/div/div[2]/div[2]/div/div[2]/input") search.send_keys("develop") time.sleep(1) search.send_keys(Keys.RETURN) time.sleep(1) driver.find_element(By.XPATH,"//*[@id='new_merge_request']/div[2]/div[2]/div/div[2]/div[2]/button/span").click() time.sleep(1) search = driver.find_element(By.XPATH,"//*[@id='new_merge_request']/div[2]/div[2]/div/div[2]/div[2]/div/div[2]/input") search.send_keys("master") time.sleep(1) search.send_keys(Keys.RETURN) time.sleep(1) driver.find_element(By.XPATH,"//*[@id='new_merge_request']/input[2]").click() time.sleep(1) driver.find_element(By.XPATH,"//*[@id='new_merge_request']/div[4]/div/div[1]/div/a").click() time.sleep(1) #search = driver.find_element(By.XPATH,"//*[@id='new_merge_request']/div[4]/div/div[1]/div/div/div/div/div[2]/input").click() #search.send_keys("Administrator") #search.send_keys(Keys.RETURN) driver.find_element(By.XPATH,"//*[@id='new_merge_request']/div[9]/span/input").click() #time.sleep(1) #driver.find_element(By.XPATH,"//*[@id='content-body']/div/div[2]/div[3]/div[2]/div[1]/div/div[1]/div[2]/div/span/button").click() #点击合并代码 from util.ClipboardUtil import Clipboard Clipboard.setText #driver.get("https://lab.yaozh.com/yaozh/top/commits/master") #driver.find_element(By.XPATH,"//*[@id="commit-a9dd4cd1"]/div[2]/div[2]/div[2]/button").click() #time.sleep(1) #复制版本号到剪切板 #crebra2 = driver.find_element(By.XPATH,"//*[@id='new-branch-form']/div[3]/button").click() #actions = ActionChains(driver) #actions.click(crebra2) #crebra2 = driver.find_element(By.XPath,'//*[@id="new-branch-form"]/div[3]/button') #ActionChains(driver).click(crebra2) #time.sleep(1) #hes = driver.find_element(By.CLASS_NAME,"dashboard-shortcuts-merge_requests") #actions = ActionChains(driver) #actions.click(hes) #newbranch = driver.find_element("",'//*[@id="new-branch-form"]/div[3]/button') #actions = ActionChains(driver) #actions.click(newbranch) time.sleep(10) driver.quit()