Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

while scarping the data from the website , every listing have a button and when we click the button , popup open but not closed in python

$
0
0

popup open but not closed, please help me to close the popup. only issue is coming here popup not closed.

color="accent" class="mat-focus-indicator mat-button mat-button-base mat-accent">... is not clickable at point (684, 847). Other element would receive the click:
(Session info: chrome=124.0.6367.61) explain the error

# Import necessary modulesfrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom webdriver_manager.chrome import ChromeDriverManagerimport csvimport time# Set up Chrome serviceservice = webdriver.chrome.service.Service(ChromeDriverManager().install())# Initialize Chrome WebDriver with the servicedriver = webdriver.Chrome(service=service)# Navigate to the webpagedriver.get("https://mmiconnect.in/app/exhibition/catalogue/ep2023")# Close the initial popup if presenttry:    # Find and click the close button if it's clickable    close_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "close-button")))    close_button.click()except:    # If close button not found, pass    pass# List to store the scraped datasiteData = []# Iterate over pagesfor nav in range(1, 33):    for i in range(1, 750):        try:            # Find and click on the buttons            listing = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'center')))            lists = listing.find_elements(By.XPATH, "//div[@class='courses']//button[contains(@class, 'mat-focus-indicator')]")            # Iterate over the buttons            for listss in lists:                try:                    # Click on the button                    listss.click()                    # Wait for the popup to appear                    time.sleep(2)                    # Check if the popup is still open                    if EC.visibility_of_element_located((By.ID, "mat-dialog-3"))(driver):                        # Wait for the popup to appear                        popup_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "mat-dialog-3")))                        # Scrape data from the popup                        table = popup_element.find_element(By.ID, "customers")                        rows = table.find_elements(By.TAG_NAME, "tr")                        table_data = []                        for row in rows:                            cells = row.find_elements(By.TAG_NAME, "td")                            row_data = [cell.text for cell in cells]                            table_data.append(row_data)                        # Write table data to CSV                        with open("mmei.csv", mode='a', newline='') as file:                            writer = csv.writer(file)                            writer.writerows(table_data)                        # Execute JavaScript to click the "Close" button within the popup                        close_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(@aria-label, 'Close dialog')]")))                        driver.execute_script("arguments[0].click();", close_button)                except Exception as e:                    # Print error if any                    print("Error processing popup:", e)                    pass        except Exception as e:            # Print error if any            print("Error iterating over pages:", e)            continue# Quit the driverdriver.quit()

Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>