Python Selenium:无法通过Xpath定位元素
我试图通过selenium单击一个保存按钮,但是,我得到一个错误,它无法定位元素 这就是我得到的错误: NoTouchElementException:没有此类元素:无法定位元素: {“方法”:“id”,“选择器”:“DivFlashViewerMain_SavePdfButtonIcon”}Python Selenium:无法通过Xpath定位元素,python,selenium,Python,Selenium,我试图通过selenium单击一个保存按钮,但是,我得到一个错误,它无法定位元素 这就是我得到的错误: NoTouchElementException:没有此类元素:无法定位元素: {“方法”:“id”,“选择器”:“DivFlashViewerMain_SavePdfButtonIcon”} (会话信息:chrome=74.0.3729.169)(驾驶员信息: 色度驱动=74.0.3729.6 (255758ECCF3D24491B8A1317AA76E1CE10D57E9参考文献/分支机构
(会话信息:chrome=74.0.3729.169)(驾驶员信息: 色度驱动=74.0.3729.6 (255758ECCF3D24491B8A1317AA76E1CE10D57E9参考文献/分支机构负责人/3729{29}),平台=窗口 新界10.0.17763 x86_64)
您应该使用
element\u使其可点击
而不仅仅是presence\u所在的元素
它应该是这样的:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("xxx")
button = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID, "DivFlashViewerMain_SavePdfButtonIcon")))
button.click()
希望这有帮助 您应该使用
元素以使其可点击
而不仅仅是元素的存在
driver.find_elements_by_css_selector('[id="DivFlashViewerMain_SavePdfButtonIcon"]')[0].click()
它应该是这样的:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("xxx")
button = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID, "DivFlashViewerMain_SavePdfButtonIcon")))
button.click()
希望这有帮助
driver.find_elements_by_css_selector('[id="DivFlashViewerMain_SavePdfButtonIcon"]')[0].click()
似乎您正在使用许多函数,例如查找id=“”。强烈建议尝试css选择器:
似乎您正在使用许多函数,例如查找id=“”。强烈建议尝试css选择器:
这应该能锁定OP。这应该能锁定OP。强烈建议使用CSS选择器。。。然而,我认为OP的问题在于等待
元素的存在(位于任何方式+1!)强烈建议使用CSS选择器。。。然而,我认为OP的问题在于等待元素的存在(位于任何方式+1!)