[英]Selenium Python: 'Close' button on pop-up window not interactable
似乎无法单击“关闭”按钮来关闭我之前打开的小狗 window 以抓取它显示的数据。 该按钮具有以下 html 脚本:
<div class="closebutton" onclick="return hs.close(this)" title="Schließen"></div>
我正在尝试以下操作:
driver.find_element_by_xpath("//div[@class='closebutton']").click()
但我得到了错误:
Message: element not interactable
任何人都知道如何使元素可交互?
要单击元素,您可以使用以下任一定位器策略:
使用css_selector
:
driver.find_element_by_css_selector("button.closebutton[title='Schließen']").click()
使用xpath
:
driver.find_element_by_xpath("//div[@class='closebutton' and @title='Schließen']").click()
理想情况下,要单击需要为element_to_be_clickable()
诱导WebDriverWait的元素,您可以使用以下任一Locator Strategies :
使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.closebutton[title='Schließen']"))).click()
使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='closebutton' and @title='Schließen']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.