0

I am trying to scrape some data from a website and every so often a pop-up appears. I am attempting to build a function which will remove the popup by pressing the "x" icon. I have tried multiple ways of clicking it but each time I just seem to get the same "element not interactable" error.

Below are my 3 different attempts:

    try:
        if driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/a').is_displayed():
            wait = WebDriverWait(driver, 10)
            element = wait.until(EC.presence_of_element_located((By.XPATH, "/html/body/div[2]/div/div[1]/a")))
            driver.execute_script("arguments[0].click();", element)
    except Exception as e:
        print(e)
try:
        if driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/a').is_displayed():
            element = driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/a')
            ActionChains(driver).move_to_element(element).click().perform()
    except Exception as e:
        print(e)
try:
        if driver.find_element_by_xpath('/html/body/div[2]/div/div[1]/a').is_displayed():
            element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//a[text()='x']")))
            driver.execute_script("arguments[0].click();", element)
    except Exception as e:
        print(e)

The html code dosn't say the "x" is a button, but rather it is text located within an tag. I am not very familiar with html so if you need it to help I can provide if needed.

Many thanks

Edit: Here's the html code for the button im trying to press:

<a data-trigger="dismiss.close" style="background:rgb(0,0,0);border-radius:100%;box-shadow:rgba(0,0,0,.6) 0 2px 6px;color:rgb(255,255,255);font-family:sans-serif;font-size:20px;font-weight:400;display:block;height:32px;line-height:32px;position:absolute;right:-15px;text-align:center;top:-15px;width:32px;cursor:pointer;bottom:auto;left:auto;z-index:99;min-width:0;max-width:none;min-height:0;max-height:none;">×</a>
Tempelis1
  • 3
  • 2
  • Can you provide the html code? Also, have you tried good old `element.click()` ? ;) – StyleZ May 20 '20 at 19:32
  • My bad, this looks like something that is generated using JavaScript, so you have to use execute script as you did, but to make it work, you should use the full-path, because `"//a[text()='x']"` might be overridden by some kinda other tag – StyleZ May 20 '20 at 19:35
  • @StyleZ I tried using the full-path but still no success :( Appreciate you trying though – Tempelis1 May 20 '20 at 19:49

0 Answers0