'How can I sort out when ads shows up on my code using Selenium Python

Below is my code and the intention behind is to access the website below, type the bond that I want to look the numbers and ENTER. But sometimes ads can show up and unfortunately I didn't have knowledge how to treat my code to run if it pops-up... Can you pls help me sort it out?

from bs4 import BeautifulSoup 
from openpyxl import Workbook
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

html = "https://statusinvest.com.br"
soup = BeautifulSoup(html, 'html.parser')
acao = "BBAS3"
navegador = webdriver.Chrome()
navegador.get(html) 
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')

input1 = navegador.find_element_by_class_name('main-search').click() 
input2 = navegador.find_element_by_xpath('//*[@id="main-search"]/div[1]/span[1]/input[2]')
input2.send_keys("BBAS3")
navegador.find_element_by_xpath('//*[@id="main-search"]/div[2]/div/div/a').click()

# navegador.find_element_by_xpath('/html/body/div[11]/div/div/div[1]/button/i').click()

When I used # navegador.find_element_by_xpath here, when the ads shows up, this is the path to click on '' X '' but I tried A LOT OF and nothing worked with '' While.. Not in... ''



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source