Everytime I run this code the window opens blank and then loads the required page for about 1 second before closing.
from selenium import webdriver
driver = w
I am using ChromeDriver 81.0.4044.138 placed in C:\Windows and this is whats working for me
from selenium import webdriver
class Stackoverflow(object):
def __init__(self):
self.options = webdriver.ChromeOptions()
self.options.add_experimental_option('useAutomationExtension', False)
self.options.add_experimental_option("excludeSwitches", ["enable-automation"])
self.driver = webdriver.Chrome(options=self.options)
self.driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
self.driver.execute_cdp_cmd("Network.enable", {})
self.driver.execute_cdp_cmd("Network.setExtraHTTPHeaders", {"headers": {"User-Agent": "browser"}})
self.driver.get("https://www.stackoverflow.com/")
if __name__ == '__main__':
Stackoverflow()