0

I've been trying to use selenium in order to google a list of airports to be able to get information from a website that I use tab to get to. It works every single time when the ads don't appear on the webpage. I've spent a bit of time trying to solve this but nothing is seeming to work. This is a fraction of my code for you guys to understand what I'm trying to do:

    driver = webdriver.Chrome()
    driver.get("https://www.google.com")
    a = driver.find_element_by_css_selector(".gLFyf")
    a.clear()
    a.send_keys(f'site:airnav.com/airport airnav {a[i]} {b[i]}')
    print(f'airnav {a[i]} {b[i]}')
    a.send_keys(Keys.RETURN)
    actions = ActionChains(driver)
    actions1 = actions.send_keys(Keys.TAB*19)
    actions1.perform()
    time.sleep(3)
    actions = ActionChains(driver)
    actions2 = actions.send_keys(Keys.ENTER)
    actions2.perform()
    act = driver.current_url

    driver = webdriver.Chrome()
    driver.get(f'https://web.archive.org/web/2015/{act}')
    time.sleep(3)

The a and b are lists, I'm googling every single element from those lists and getting to the same website. The only thing that ever stops the TAB method from working are these ads that keep appearing every second time I try this.

Ysgramor 500
  • 13
  • 1
  • 4
  • have you tried running your browser headless ? https://stackoverflow.com/questions/46920243/how-to-configure-chromedriver-to-initiate-chrome-browser-in-headless-mode-throug – StyleZ May 13 '21 at 22:42
  • I've not, but the problem is the ads that keep appearing. They are like a bunch of different links leading to different pages, just like a normal link that would appear when you do a normal search on google, the only difference's that it says "ad" beside them – Ysgramor 500 May 13 '21 at 23:21

1 Answers1

0

Disable pop-ups in Chrome

For Chrome, pop-ups are enabled by default i.e. the pop-up blocker is disabled by default. To enable the pop-up blocker i.e. to block pop-ups, pass disable-popup-blocking argument under the excludeSwitches of a chromeOptions capability, as shown below:

Code :

options = webdriver.ChromeOptions()
capabilities = options.to_capabilities()
capabilities = {
 'browser': 'chrome',
 'browser_version': 'latest',
 'os': 'Windows',
 'os_version': '10',
 'build': 'Python Sample Build',
 'name': 'Pop-ups testing'
}
capabilities["chromeOptions"]["excludeSwitches"] = ["disable-popup-blocking"]
#options.add_argument("--headless")
driver = webdriver.Chrome("C:\\Users\\etc\\Desktop\\Selenium+Python\\chromedriver.exe", options=options)
driver.get("Your URL")
cruisepandey
  • 28,520
  • 6
  • 20
  • 38