在网页上,此元素是唯一包含确切文本“Volgende stap”的元素:<span class="b-button--label ng-binding ng-scope" ng-if="arrowDirection === 'right'">Volgende stap</span>但是当我尝试使用 xpath 选择(一个列表)包含这些单词的元素时:driver.find_elements_by_xpath("//span[contains(text(),'Volgende')]")driver.find_elements_by_xpath("//span[.='Volgende stap']")driver.find_elements_by_xpath("//span[text()='Volgende stap']")我不断得到一个空列表(或者element not found在find_element代替 的情况下find_elements)。这是我正在处理的 html 页面的脚本:from selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWait as waitdriver = webdriver.Chrome()driver.get("https://www.greetz.nl/kaarten/verjaardag/man")wait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[href*='/kaart/detail/greetz-verjaardagskaart---abracadabra/1142778148']"))).click()wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Kaart bewerken']"))).click()
2 回答
哆啦的时光机
TA贡献1779条经验 获得超6个赞
它在一个 iframe 中。首先切换到它,然后尝试通过文本查找:
frame = driver.find_element_by_css_selector('frame.personalize--frame')
driver.switch_to.frame(frame)
添加回答
举报
0/150
提交
取消