[英]Selenium Python: 'Close' button on pop-up window not interactable
Can't seem to click on a 'close' button to close a pup up window that I have opened before to scrape the data that it displays.似乎无法单击“关闭”按钮来关闭我之前打开的小狗 window 以抓取它显示的数据。 The button has the following html script:
该按钮具有以下 html 脚本:
<div class="closebutton" onclick="return hs.close(this)" title="Schließen"></div>
I was trying the following:我正在尝试以下操作:
driver.find_element_by_xpath("//div[@class='closebutton']").click()
But I get the error:但我得到了错误:
Message: element not interactable
Anyone have a clue how to make the element interactable?任何人都知道如何使元素可交互?
To click on the element you can use either of the following Locator Strategies :要单击元素,您可以使用以下任一定位器策略:
Using css_selector
:使用
css_selector
:
driver.find_element_by_css_selector("button.closebutton[title='Schließen']").click()
Using xpath
:使用
xpath
:
driver.find_element_by_xpath("//div[@class='closebutton' and @title='Schließen']").click()
Ideally, to click on the element you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies :理想情况下,要单击需要为
element_to_be_clickable()
诱导WebDriverWait的元素,您可以使用以下任一Locator Strategies :
Using CSS_SELECTOR
:使用
CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.closebutton[title='Schließen']"))).click()
Using XPATH
:使用
XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='closebutton' and @title='Schließen']"))).click()
Note : You have to add the following imports:注意:您必须添加以下导入:
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.