我正在尝试使用openpyxl从excel文件中读取一个名称(转换为变量名称placeHolder),以便可以迭代一系列Webelements,然后单击与placeHolder相等的Webelements。从excel读取的数据可以很好地工作,但是单击(特别是e.click())只能工作一半时间。
任何帮助将不胜感激!
browser.switch_to.frame("DialogWindow")
ele = browser.find_elements_by_tag_name('a')
for e in ele:
if e.text == placeHolder: #The variable being read in from and excel file using openpyxl
try:
e.click() #only works sometimes
except:
print("Element was not clicked")
break
time.sleep(2)
browser.switch_to.default_content()
time.sleep(1)
browser.find_element_by_css_selector('#ctl00_ContentPlaceHolder1_ucDashboard_ucPortfolioContainer_ctl01_tblAccounts > tbody > tr:nth-child(3) > td:nth-child(2) > a').click()