Created
March 20, 2018 02:41
-
-
Save hsienwei/233b85fbcccc47b23f27266317c6dfce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf8 | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.support.wait import WebDriverWait | |
ID = 'id' # your id. | |
PWD = 'password' # your password | |
PARENT_ISSUE = [1808] | |
def check_login(web): | |
web.get('http://ip.address/secure/IssueNavigator.jspa?mode=hide') # fill your ip | |
try: | |
title_login = web.find_element_by_id('header-details-user') | |
link_elm = title_login.find_element_by_tag_name('a') | |
title = link_elm.text | |
print(title) | |
if title == '登录': | |
print('enter login') | |
link = link_elm.get_property("href") | |
web.get(link) | |
id_input = web.find_element_by_id('login-form-username') | |
pwd_input = web.find_element_by_id('login-form-password') | |
form = web.find_element_by_id('login-form') | |
id_input.send_keys(ID) | |
pwd_input.send_keys(PWD) | |
form.submit() | |
except Exception as e: | |
print ('header-details-user not found') | |
def get_list(web): | |
list = [] | |
web.get('http://ip.address/secure/IssueNavigator.jspa?mode=show&createNew=true') # fill your ip | |
proj_select = web.find_element_by_id('searcher-pid') | |
for option in proj_select.find_elements_by_tag_name('option'): | |
print(option.text) | |
if option.text == 'project name': | |
option.click() | |
block_who = web.find_element_by_id('navigator-filter-subheading-issueattributes-group') | |
open_link = block_who.find_element_by_tag_name('legend') | |
open_link.click() | |
who_select = web.find_element_by_id('searcher-assigneeSelect') | |
for option in who_select.find_elements_by_tag_name('option'): | |
print(option.text) | |
if option.text == '当前用户': | |
option.click() | |
state_select = web.find_element_by_id('searcher-status') | |
for option in state_select.find_elements_by_tag_name('option'): | |
print(option.text) | |
if option.text == '开启': | |
option.click() | |
form = web.find_element_by_id('issue-filter') | |
form.submit() | |
try: | |
issue_table = web.find_element_by_id('issuetable') | |
tbody = issue_table.find_element_by_tag_name('tbody') | |
for item in tbody.find_elements_by_tag_name('tr'): | |
parent_issue_obj = item.find_element_by_class_name('parentIssue') | |
parent_issue = parent_issue_obj.text | |
idx = parent_issue.find('-') | |
pid = int(parent_issue[idx + 1:]) | |
if pid in PARENT_ISSUE: | |
print('=') | |
print(parent_issue) | |
print(parent_issue_obj.get_property("href")) | |
key = item.find_element_by_xpath("./td[@class='nav issuekey']/a") | |
print(key.get_property("href")) | |
list.append(key.get_property("href")) | |
except Exception as e: | |
print ('find error') | |
print (e) | |
return list | |
def add_command(web, content): | |
command_btn = web.find_element_by_xpath("//a[@class='first last button']") | |
command_btn.click() | |
textarea = web.find_element_by_xpath("//textarea[@class='textarea long-field mentionable']") | |
textarea.send_keys(content) | |
form = web.find_element_by_id('issue-comment-add') | |
form.submit() | |
def kick_to_another_one(web, who): | |
# ref : https://huilansame.github.io/huilansame.github.io/archivers/sleep-implicitlywait-wait | |
link = web.find_element_by_xpath("//a[@class='button issueaction-assign-issue opsbar-operations first']") | |
link.click() | |
locator = (By.ID , 'assignee-field') | |
WebDriverWait(web, 20, 1).until(EC.presence_of_element_located(locator)) | |
input = web.find_element_by_id('assignee-field') | |
input.send_keys(who) | |
input.send_keys(Keys.ENTER); | |
locator = (By.ID , 'assign-issue-submit') | |
WebDriverWait(web, 20, 1).until(EC.presence_of_element_located(locator)) | |
send = web.find_element_by_id('assign-issue-submit') | |
send.click() | |
if __name__ == "__main__": | |
web = webdriver.Chrome(executable_path=r'.\chromedriver.exe') | |
check_login(web) | |
list = get_list(web) | |
for i in list: | |
web.get(i) | |
add_command(web, '測試功能已完成, 等待美術出版') | |
kick_to_another_one(web, 'someone@mail.net') # fill the Unlucky guy mail. | |
web.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment