我想遍历html元素在网页中删除它们。对于一个实例在购物车中的项目太多(这不是购物车,虽然)。
项目数是> 50。
但是,单击第一个项目后退出循环下,任何以为我失去了什么?
for i in range(0, len(x)):
time.sleep(2)
if x[i].is_displayed():
print(i)
pageClicked = WebDriverWait(driver, 2).until(
ec.element_to_be_clickable((By.XPATH,
"/html/body/div/div/div/div/router-view/div[1]/div/div[1]")))
pageClicked.click()
x[i].click() #removes the item
"""This is hardcoded part, TODO remove this """
removalConfirm = WebDriverWait(driver, 2).until(
ec.element_to_be_clickable((By.XPATH, "/html/body/ux-dialog-container/div/div/ux-dialog/ux-dialog-body/form/div[2]/button[1]")))
#
""""remove from the wishlist """
removalConfirm.click() #receive confirmation
i=i+1
在飞行的DOM对象改变了,所以我不得不重新夺回DOM对象。下面的工作。
x = driver.find_elements_by_id(
ObjectManager().getObjectIdentifierValue(driver, "Patron", "WishlistPage", "wishListCloseAll"))
#print(len(x))
for i in range(0, len(x)-1):
time.sleep(2)
"""Since the dom objects change on the fly, they need to named"""
x = driver.find_elements_by_id(
ObjectManager().getObjectIdentifierValue(driver, "Patron", "WishlistPage", "wishListCloseAll"))
#print('lenght of x', len(x))
if x[i].is_displayed():
if x[i].is_displayed():
x[i].click()
#print('x', x[i])
"""This is hardcoded part, TODO remove this """
removalConfirm = WebDriverWait(driver, 2).until(
ec.element_to_be_clickable((By.XPATH, "/html/body/ux-dialog-container/div/div/ux-dialog/ux-dialog-body/form/div[2]/button[1]")))
#
""""remove from the wishlist """
removalConfirm.click()
i=i
#print(i)
time.sleep(2)