-4
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome("C:\\chromedriver\\chromedriver.exe")
driver.maximize_window()
driver.get("https://www.arttoframe.com/")
time.sleep(6)
driver.close()

Console Logs :

C:\Users\Dell\PycharmProjects\untitled\venv\Scripts\python.exe 
C:/Users/Dell/PycharmProjects/untitled/newaaa.py

Process finished with exit code 0
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

2

As you have created an instance of ChromeOptions() as chrome_options you need to pass it as an argument to put the configurations in effect while invoking webdriver.Chrome() as follows :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("start-maximized")
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get("https://www.arttoframe.com/")
time.sleep(6)
driver.quit()

Note :

  • To maximize the Chrome browser instead of maximize_window() use the ChromeOptions() class argument start-maximized
  • At the end of your program instead of driver.close() use driver.quit().
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
1
driver.switch_to_alert().dismiss()
driver.switch_to_alert().accept()

These can be used dismiss-right and accept-left

  • Hello! While this code may solve the question, [including an explanation](https://meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Brian61354270 Apr 21 '20 at 01:02