skip to Main Content

I’m trying to close a frame on this page.

What I want is to click in here:

enter image description here

It seems to be easy, but so far the following code (which should work) has failed:

import selenium.webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = selenium.webdriver.Chrome()
driver.maximize_window()
driver.get('https://www.bvc.com.co/variable-income-local-market/cemargos?tab=issuer-information')

#X(close) bvc frame
xpath = '//*[@id="__next"]/div/div[1]/div/div[1]/div/div/div/div/div[3]/div/div/div/div[3]/div[2]/span'
class_name = 'sc-843139d2-14 iVPGqd'

# Trying with XPath
if 1:
    try:
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, xpath))).click()
    except:
        driver.find_element(By.XPATH, xpath).click()

# Trying with class_name
if 1:
    try:
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, class_name))).click()
    except:
        driver.find_element(By.CLASS_NAME, class_name).click()

The output using XPath:

raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
#0 0x64a95375031a <unknown>
...

The output using class_name:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".sc-843139d2-14 iVPGqd"}

2

Answers


  1. A simple way to close that popup is to click the ‘X’. You can do that using the XPath below,

    //span[text()='X']
    
    Login or Signup to reply.
  2. you need to raise the WebDriverWait because it seems that 10 sec is not enough, try raising it to 30 sec and then reduce it until you find the minimum that the script should wait, if the element is not located yet try to use this path

    //span[text()='X']
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search