pythonseleniumiframewebdriverwaitaliexpress

How to click and close the banner after accessing the website https://www.aliexpress.com/ using Python and Selenium


I'm trying to access a well known online shopping service, to filter and sort results, however the service has a "popup" offering coupons when you first open the site. I'm trying to dismiss the message. The problem is the popup, isn't a real popup, it's a series of div and img tags which are dynamically created shortly after visiting the homepage.

I've tried searching by class, Xpath, CSS but no luck. Can anyone tell me what I'm doing wrong

driver = webdriver.Chrome(options=opts, executable_path='chromedriver')
driver.delete_all_cookies()
driver.get('https://www.aliexpress.com/')

timeout = 30

try:
    WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.XPATH,'//*[@id="6216442440"]/div/div/img')))
except TimeoutException:
    driver.quit()

Solution

  • The element to dismiss the message is within an <iframe> so you have to:

    aliexpress_deals


    Reference

    You can find a couple of relevant discussions in: