selenium-webdriverselenium-chromedrivergoogle-chrome-headless

Disable search engine choice screen with Chrome and selenium


Since Google Chrome 127.0.6533.72, my python script with selenium fails on the selecting default search engine screen.

I tried to implement the code suggested here: Selecting default search engine is needed for Chrome version 127

But probably because my code specifies the location of the driver and uses an instance of the applicable Service class, it doesn't work and complains about the driver location ("selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome").

My code:

import time
from parsel import Selector
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

class Test:

    def __init__(self):
        self.email = Test.email
        self.password = Test.password
        self.searchs = Test.searchs
        self.base_domain = "https://www.test.com"
        self.s = Service('./chromedriver')
        self.driver = webdriver.Chrome(service = self.s)

Could you please help me to implement this disable-search-engine-choice-screen option in this code?

Thanks for your kind help


Solution

  • You can use also class Service and class Options like below in last line:

    from selenium.webdriver.chrome.options import Options
    
    chrome_options = Options()
    chrome_options.add_argument("--disable-search-engine-choice-screen")
    self.driver = webdriver.Chrome(options=chrome_options, service=self.s)