使用Selenium和Python选择有关描述文本的元素
我正在尝试使用以下代码查找并单击包含的屏幕截图中的燕麦(ADS05 ....)的位置:
oatObj = driver.find_element(By.XPATH,"//span[contains(@class, 'treeImg') and contains(., 'OAT ')]")
oatObj.click()
这是弹出以下错误:
ElementNotInteractableException: Message: element not interactable
绝对可以单击此元素,以及我正在使用类似XPath匹配的代码中的其他位置。这个XPath有什么不同的东西吗?这是元素的屏幕截图,然后单击时检查窗格:
I'm trying to use the following code to find and click where it says OAT (ADS05....) in the included screenshot:
oatObj = driver.find_element(By.XPATH,"//span[contains(@class, 'treeImg') and contains(., 'OAT ')]")
oatObj.click()
This is popping up the following error:
ElementNotInteractableException: Message: element not interactable
This element is definitely clickable, and other places in the code I'm using a similar XPATH match which do work. Is there something different about this XPATH that anyone can see? Here's a screenshot of the element and inspect pane when clicked:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Innertext确实包含文本 燕麦 ,但在规范上,文本
start with-with with
text 燕麦解决方案
要单击 单击 元素理想情况下您需要诱导 WebDriverWait 对于以下 定位器策略 :
使用 xpath :< /p>
注意:您必须添加以下导入:
The innerText does contains the text OAT but canonically the text
starts-with
the text OATSolution
To click on the clickable element ideally you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategy:
Using XPATH:
Note: You have to add the following imports :
尝试在单击元素之前先
使用
等待
Try to use wait before click on the element
And also you can use
find_elements
if there are more elements with same xpathYou can change you way to click by using Java Script and perform Action
element notintactableException:消息:元素不相互作用
您遇到的错误,因为该元素在访问它的位置无法交互。可能是各种原因,有时不可见并尝试单击,有时会与其他元素覆盖,有时是视口。请找到以下解决方案。
#1使用
WebDriverWait()
#2使用
Action class
#3使用
JavaScripts executor
请在库下导入:
ElementNotInteractableException: Message: element not interactable
error you are getting because the element is not interactable at the point of accessing it. May be various reason, sometimes it is not visible and trying to click, sometimes overlay with other elements, sometimes for viewport.Please find following solutions.
#1 using
WebDriverWait()
#2 using
Actions class
#3 using
JavaScripts Executor
Please import below libraries: