Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (18.4k points)

I am trying to close the popup iframe to do web scraping in the aliexpress, but I can't access my image to click it

This is my code:

import os

from selenium import webdriver

from selenium.webdriver.firefox.options import Options

from import By

from import WebDriverWait

from import expected_conditions as EC

option = Options()


profile = webdriver.FirefoxProfile()

profile.set_preference('intl.accept_languages', 'fr')

def webscraping_aliexpress():

    driver = webdriver.Firefox(executable_path=f"{os.getcwd()}\geckodriver.exe", firefox_profile=profile)

    driver.get(str(input("Paste aliexpress url: ")))

    name = driver.find_element_by_xpath("//h1[@class='product-title-text']").text

    price = driver.find_element_by_xpath("//div[@class='product-price-current']").text

    WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@data-spm-anchor-id='a2g0o.detail.0.i4.4bc257b6555T2w'")))

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//img[@class='rax-image ']"))).click()


I can extract some of the data, like name and price before the popup shows on, but he blocks other operations after.

1 Answer

0 votes
by (36.8k points)

You need to switch content to the iframe

iframe = driver.find_element_by_xpath('//iframe[contains(@src, "__poplayer")]')


# code of closing popup here


 Want to gain skills in Data Science with Python? Sign up today for this Python for Data Science Course and be a master in it

Related questions

0 votes
1 answer
0 votes
1 answer
asked Nov 1, 2020 in Data Science by blackindya (18.4k points)
0 votes
1 answer
asked Nov 1, 2020 in Data Science by blackindya (18.4k points)

Browse Categories