我试图增加变量“xpath”,但它无法处理下面的代码。有人知道我怎么解决这个问题吗?如果我不使用该函数,内部循环将不起作用,因此我需要保持该部分的状态(据我所知)
任何帮助都将不胜感激!提前谢谢
#Function to export data
def loop_function():
#Search client
searchCustomerButton = driver.find_element_by_xpath('//*[@id="ibSearchPatient"]')
searchCustomerButton.click()
#Loop client ID's
followLoop = range(0, 10)
for x in followLoop:
xpath = '//*[@id="ctl00_CPH_Main_ctl00_RadGrid_Patienten_ctl00__'
xpath += str(x)
xpath += '"]/td[3]'
#Click on cliënt ID
driver.find_element_by_xpath(xpath).click()
#Click on Zorgtraject
zorgtrajectButton = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Top_ToolBar_MenuCurrentPage"]/div/ul/li[3]/a/span/span/span')
zorgtrajectButton.click()
#Loop Zorgtraject ID's
followLoop2 = range(0,10)
for x in followLoop2:
try:
xpath2 = '//*[@id="ctl00_CPH_Main_ctl00_RadGrid1_ctl00__'
xpath2 += str(x)
xpath2 += '"]/td[2]'
#Click on Zorgtraject ID
driver.find_element_by_xpath(xpath2).click()
#Dossier button
dossierButton = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Top_ToolBar_MenuCurrentPage"]/div/ul/li[5]/a/span/span/span')
dossierButton.click()
#Dropdown select
dropdownSelector = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_Verslagen_radGridBehandelVerloop_ctl00_ctl03_ctl01_PageSizeComboBox_Arrow"]')
dropdownSelector.click()
#Prevent not interactable error
time.sleep(2)
#Select 50
selectDropdown = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_Verslagen_radGridBehandelVerloop_ctl00_ctl03_ctl01_PageSizeComboBox_DropDown"]/div/ul/li[4]')
selectDropdown.click()
#Check all documents
tickDossier = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_Verslagen_radGridBehandelVerloop_ctl00_ctl02_ctl01_headerChkboxPrint"]')
tickDossier.click()
#Click print
printButton = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Main_ctl00_Verslagen_btnPrintBehandelverloop"]')
printButton.click()
#Click on Zorgtraject ID
zorgtrajectButton2 = driver.find_element_by_xpath('//*[@id="ctl00_CPH_Top_ToolBar_MenuCurrentPage"]/div/ul/li[3]/a/span/span/span')
zorgtrajectButton2.click()
#If no Zorgtraject ID, start function over
except NoSuchElementException:
loop_function()
exec(loop_function())
你试过使用f字串吗
但是,如果这个模式总是正确的,我更愿意使用
starts-with
一次找到所有元素,然后循环我想您可以通过元素循环并在NoTouchElementException时打破第二个循环来完成您想要的:
相关问题 更多 >
编程相关推荐