Untitled
Navigate pagination, scan table links, find unique workflowsunknown
python
2 years ago
1.4 kB
10
Indexable
def get_workflows_from_page(driver, uniq_workflows):
#get all workflow names in current page
//*[@id="content"]/div[2]/div[2]/table/tbody[1]/tr[1]/td[1]/a[2]
page_elements = driver.find_elements(By.XPATH, '//*[@id="content"]/div[2]/div[2]/table/tbody/tr[1]/td[1]/a[2]');
for ele in page_elements:
workflow_name = ele.get_attribute('innerHTML');
uniq_workflows.add(workflow_name);
return uniq_workflows;
#Code inside the main calling method
total_pages = driver.find_element(By.ID, '//*[@id="content"]/div[2]/div[2]/table/tfoot/tr/td/div[1]/span').get_attribute('innerHTML');
print(f'total pages : {total_pages}')
uniq_workflows = set(); #to store all unique workflow names
#Navigate through each page and find workflows
for page_num in range(total_pages):
print(f'current page : {page_num+1}');
uniq_workflows = get_workflows_from_page(driver, uniq_workflows);
print(uniq_workflows);
#click and go to next page
next_page = driver.find_element(By.XPATH, '//*[@id="content"]/div[2]/div[2]/table/tfoot/tr/td/ul/li[3]/span').click()
#find the <a> tag by workflow names
link_list = []; #to store all links required
for workflow in uniq_workflows:
linkElement = driver.find_element(By.XPATH, f'//a[text()="{workflow}"]');
link = linkElement.get_attribute('href');
print(f'Link for {workflow} : {link}');
link_list.append(link);Editor is loading...
Leave a Comment