0

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. The button has the following html script:

<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?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
davvpo
  • 39
  • 3

1 Answers1

1

To click on the element you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element_by_css_selector("button.closebutton[title='Schließen']").click()
    
  • Using 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:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.closebutton[title='Schließen']"))).click()
    
  • Using 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the response, I already tried webdriver wait and Css selector. I think the issue is the pop-up window. Funny is though that I can scrape the data within the pop up window but I can't activate the close button for whatever reason. – davvpo Jan 11 '21 at 02:11
  • @davvpo Did you try any of the options from the answer? What error do you see? – undetected Selenium Jan 11 '21 at 02:22
  • yes I did, I tried both with XPATH in the first place. CSS Selector has same issue. When using Webdriver.wait I get a time out error: TimeoutException: Message: – davvpo Jan 11 '21 at 02:35
  • When using the normal option its: 'Message: element not interactable' for XPATH and 'Message: element not found' for CSS Selector – davvpo Jan 11 '21 at 02:36
  • @davvpo From a generic perspective `
    ` tag aren't clickable, does the `
    ` have a child, maybe a ``?
    – undetected Selenium Jan 11 '21 at 02:37
  • unfortunately not. doesn't have a child and parent is also `
    `
    – davvpo Jan 11 '21 at 02:52
  • But does ist help if it has an "on click" attribute, because it does – davvpo Jan 11 '21 at 02:53