按钮元素不可交互 Selenium
我正在尝试编写一个脚本来使用 Selenium 和 Python 自动执行某些任务,每次尝试单击按钮时
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
driver = webdriver.Chrome(options=options)
xpath = "/html/body/app-root/app-prime/div/mat-sidenav-container//app-detail-component/main//div/span/button[@aria-label='Prenota']"
# Wait for the element to be visible, always true
WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, xpath)))
# Try to click on element, get an error
driver.find_element(By.XPATH, xpath).click()
都会收到以下错误,
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
我确信该元素已正确定位并且必须匹配,但它应该仅对第一个进行操作。
我尝试过:
- 尝试单击子标签,例如其他div和span
- 等待它可单击
- 等待隐式等待
这些活动都没有成功
编辑:显然我的机器上存在olly问题
I'm trying to write a script to automate some tasks with Selenium and Python, and every time I try to click on a button
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
driver = webdriver.Chrome(options=options)
xpath = "/html/body/app-root/app-prime/div/mat-sidenav-container//app-detail-component/main//div/span/button[@aria-label='Prenota']"
# Wait for the element to be visible, always true
WebDriverWait(driver, 5).until(expected_conditions.presence_of_element_located((By.XPATH, xpath)))
# Try to click on element, get an error
driver.find_element(By.XPATH, xpath).click()
I get the following error
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I know for sure that the element gets located correctly and has to match, but it should act only on the first one.
I tried:
- Trying to click child tags, such as others divs and span
- Waiting for it to be clickable
- Waiting with an implicit wait
None of those activities were successful
Edit: Apparently the issue olly exist on my machine
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于多种原因,它可能无法点击。您可能想检查页面上是否有某些元素位于顶部,以便该元素当时不可交互,例如某些弹出窗口/iframe 等。当时可能还有其他一些元素会收到点击。
您可以尝试单击操作 - 像这样
It could be not clickable for a number of reasons. You might want to check if there is some element on the page layered on top so that that element is not interactable at that time, e.g some popup/iframe etc. There could be some other element that will receive click at that time.
You could try an actions click - something like this
其中之一应该有效。
注意 - 这些是 C 锐代码。尝试在java中做同样的事情。
One of this should work.
Note - these are c sharp code. try to do the same in java.