from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import TimeoutException
class getDB:
def __init__(self,login,passwd):
self.login = login
self.passwd = passwd
def getBugDB(self,url,isClosed):
opt = webdriver.ChromeOptions()#使用Chrome浏览器作为驱动器
driver = webdriver.Chrome(options=opt)
driver.set_page_load_timeout(2)#网页加载2秒后就执行登录操作,无需等待网页完全加载完毕
try:
driver.get(url)
except TimeoutException:
driver.maximize_window()
username = driver.find_element_by_xpath('//*[@id="account"]')
username.send_keys(self.login)
password = driver.find_element_by_xpath('//*[@id="loginPanel"]/div/div[2]/form/table/tbody/tr[2]/td/input')
password.send_keys(self.passwd)
login_button = driver.find_element_by_xpath('//*[@id="submit"]')
login_button.click()
time.sleep(2)
if isClosed:#通过判定条件来决定是下载所有BUG的数据库,或是未关闭BUG的数据库
#选择所有BUG页面
scale = driver.find_element_by_xpath('//*[@id="mainMenu"]/div[2]/a[1]')
ActionChains(driver).move_to_element(scale).perform()
driver.find_element_by_xpath('//*[@id="mainMenu"]/div[2]/a[1]').click()
# 点击导出数据按钮
output = driver.find_element_by_xpath('//*[@id="mainMenu"]/div[3]/div/button')
ActionChains(driver).move_to_element(output).perform()
driver.find_element_by_xpath('//*[@id="mainMenu"]/div[3]/div/button').click()
driver.find_element_by_xpath('//*[@id="exportActionMenu"]/li/a').click()
else:
#选择未关闭BUG页面
output = driver.find_element_by_xpath('//*[@id="mainMenu"]/div[3]/div/button')
ActionChains(driver).move_to_element(output).perform()
driver.find_element_by_xpath('//*[@id="mainMenu"]/div[3]/div/button').click()
# 点击导出数据按钮
driver.find_element_by_xpath('//*[@id="exportActionMenu"]/li/a').click()
#定制导出csv文件的格式
driver.switch_to.window(driver.window_handles[-1])
output_frame = driver.find_element_by_xpath('//*[@id="iframe-triggerModal"]')
driver.switch_to.frame(output_frame)
driver.find_element_by_xpath('//*[@id="encode"]/option[2]').click()
driver.find_element_by_xpath('//*[@id="exportType"]/option[1]').click()
#点击导出按钮
driver.find_element_by_xpath('//*[@id="submit"]').click()
time.sleep(10)
bug = getDB(login, passwd)
bug.getBugDB(url_1,True)
bug.getBugDB(url_2,True)
[Python] [Selenium] Secuencia de comandos de operación de la página web
Supongo que te gusta
Origin blog.csdn.net/qq_33868661/article/details/114326654
Recomendado
Clasificación