I am trying to close a google ad by clicking on the x, but I try to locate it with fullxpath and it does not find it when executing the code. Try another way to click starting from the body about 5 pixels to the right and down, since I noticed that clicking anywhere the advertising disappears, even so I have not been successful. I hope you can help me, since I'm still stuck here.
Below I leave my code that I made with the solutions that I made.
WebDriverWait(driver, 5) \
.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div[1]/div[1]/div'))) \
.click()
# Libraries
from threading import Thread
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
import pandas as pd
# Options of navigation
options = webdriver.ChromeOptions()
options.add_argument('--start-maximized')
options.add_argument('--disable-maximized')
options.add_argument('User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0')
driver_path = 'C:\\Users\\franc\\Downloads\\chromedriver.exe'
driver = webdriver.Chrome(driver_path, chrome_options=options)
# Inicializamos el navegador
driver.get('https://cursosdev.com/coupons')
# Ubicamos el boton de siguiente y le damos click
last_page = driver.find_element_by_xpath('/html/body/main/div[5]/div/nav/nav/div[2]/div[2]/span/a[12]')
WebDriverWait(driver, 5) \
.until(EC.element_to_be_clickable((By.XPATH, last_page))) \
.click()
# Cerramos la publicidad de Google
# METODO 1 - Ubicamos la x en la publicidad para cerra
close_publicity = driver.find_element_by_xpath('/html/body/div/div/div[1]/div[1]/div')
WebDriverWait(driver, 5) \
.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/div/div[1]/div[1]/div'))) \
.click()
# METODO 2 - Desde body movemos el mouse 5 pixeles a la derecha y abajo, y damos click para que desaparesca la publicidad
el=driver.find_element_by_tag_name("body")
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(el, 5, 5)
action.click()
action.perform()