ul=WebDriverWaitdriver10005untilECpresence_of_element_locatedByXPATHhtmlbodydiv60div1divdivdiv1div2div2divdiv2divdivdivulli2ulliul#获取ul下所有子标签li_list=WebDriverWaitul10005untilECpresence_of_element_loca
The error message "'WebElement' object is not iterable" means that you are trying to iterate over a single WebElement object, but it is not iterable. In your code, the variable li_list is assigned a single WebElement, which is why you are getting this error.
To fix this issue, you need to modify your code to find multiple elements instead of a single element. You can use find_elements instead of find_element to find all the li elements under the ul. Here's the modified code:
ul = WebDriverWait(driver, 100, 0.5).until(EC.presence_of_element_located((By.XPATH,'/html/body/div[60]/div[1]/div/div/div[1]/div[2]/div[2]/div/div[2]/div/div/div/ul/li[2]/ul/li/ul')))
# Get all li elements under ul
li_list = ul.find_elements(By.XPATH, 'li')
for li in li_list:
li.find_element(By.CLASS_NAME, 'refer-tree-title').click()
driver.find_element(By.XPATH, '/html/body/div[62]/div[1]/div/div/div[1]/div[2]/div[3]/div[2]/button[1]').click()
driver.find_element(By.XPATH, '//*[@id="modal"]/div/div/div[1]/div/div[3]/div/div[2]/div[2]/div[2]/div[1]/button').click()
driver.find_element(By.XPATH, '//*[@id="modal"]/div/div/div[1]/div/div[4]/button[1]').click()
This code will find all the li elements under the ul and iterate over each li element
原文地址: http://www.cveoy.top/t/topic/h72o 著作权归作者所有。请勿转载和采集!