Answer the question
In order to leave comments, you need to log in
How to add AdBlock ad blocker in Selenium webdriver?
Hello, when parsing, I had a task - to collect customer phone numbers. I do this using Selenium chromedriver, as I need to press a button to make the phone appear. I coped with this task, the parser works, but I have a problem that due to pop-up ads on the site, Selenium sometimes cannot click on the button.
I found out that it is possible to integrate AdBlock into Selenium. I tried looking for documentation but didn't find anything.
I would like to receive links to resources where I can learn more about this Selenium function.
Since I still met similar questions on the net, and there were some solutions: here!
I also have a question, where can I get the AdBlock files themselves in order to use them as in the example?
Is it possible to use extension files from Google Chrome that I found in the browser files, that is, I will specify the path to these files, will this work?
Answer the question
In order to leave comments, you need to log in
You can not invent bicycles, but use a permanent profile.
Both options are working 100 pistons !
Tested personally on Linux Mint 19.3 and Windows 10 20H2.
If the profile doesn't exist when you start it, chrome creates it. When you close the profile, it is saved and picks it up with all the settings and extensions the next time you start it.
Code (for Linux):
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=/home/sergey/SeleniumProfile")
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://google.com")
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\profile")
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://google.com")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question