1 回答

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超5個(gè)贊
當(dāng)您的腳本試圖對其執(zhí)行某些操作的元素的屬性發(fā)生更改時(shí),會發(fā)生陳舊元素異常。如果你想點(diǎn)擊帶有文本“XXX”的跨度,你可以直接點(diǎn)擊它:
WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//a[span[text()='XXX']]")))
如果您的要求是遍歷所有這些元素,那么:
connections=driver.find_elements_by_css_selector("a span[class='mn-connection-card__name t-16 t-black t-bold']")
print(len(connections))
for i in range(len(connections)):
connections=driver.find_elements_by_css_selector("a span[class='mn-connection-card__name t-16 t-black t-bold']") #Created Fresh element list, so it wont be stale
if connections[i].text == "XXX"
connections[i].click
break
添加回答
舉報(bào)