0

so i have just started to learn python and as a form of practice i just want the python to execute the following commands:- 1.Goto Reddit 2.Log in 3.Create a Post 4.Enter post contents 5.Click "Post" to post the content

All is well and i have done this but there is one problem,on the last step chrome displays the notification "Reddit would like to send notification".If any has the selector for the "block" button that appears on the dialog it would be very helpful or if anyone can tell me how i can add command line arguements so that the dialog does not show up at all.Thank you I will leave my code below just in case.This is just a simple thing that i wanted to do as im upping the difficulty by trying new things with python.This isnt a serious project or something.Consider it an equivalent to printing Hello Word

    from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#Setting the chrome driver location 
browser = webdriver.Chrome(executable_path=r'C:\Selenium\chromedriver.exe')

#Which Link to goto inorder to submit a post 
browser.get('https://www.reddit.com/login/?dest=https%3A%2F%2Fwww.reddit.com%2Fsubmit')
#Telling the code what to write in the username feild when asked for an ID/Password 
browser.find_element_by_css_selector('#loginUsername').send_keys("******")
##Telling the code what to write in the username feild when asked for an ID/Password 
browser.find_element_by_css_selector('#loginPassword').send_keys("******" + Keys.ENTER)
#Telling the browser to wait 10 seconds so that the next page loads
wait = WebDriverWait(browser, 10)
#When the following element will be present on said page the code will automatically type "Hello World in the tittle feild" 
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#SHORTCUT_FOCUSABLE_DIV > div:nth-child(4) > div > div > div > div._3ozFtOe6WpJEMUtxDOIvtU > div._1vyLCp-v-tE5QvZovwrASa > div._1OVBBWLtHoSPfGCRaPzpTf._3nSp9cdBpqL13CqjdMr2L_._2udhMC-jldHp_EpAuBeSR1.PaJBYLqPf_Gie2aZntVQ7 > div.HOFZo2X7Fr6JVBztpsByj > div._3w_665DK_NH7yIsRMuZkqB > div._1zq6UabIEJJ-z9grsiCJY7 > div._3zkbHfhLbXp21FwGj_kNZV > div > textarea'))).send_keys("Hello World")
#CSS selector for the content feild 
browser.find_element_by_css_selector('#SHORTCUT_FOCUSABLE_DIV > div:nth-child(4) > div > div > div > div._3ozFtOe6WpJEMUtxDOIvtU > div._1vyLCp-v-tE5QvZovwrASa > div._1OVBBWLtHoSPfGCRaPzpTf._3nSp9cdBpqL13CqjdMr2L_._2udhMC-jldHp_EpAuBeSR1.PaJBYLqPf_Gie2aZntVQ7 > div.HOFZo2X7Fr6JVBztpsByj > div._3w_665DK_NH7yIsRMuZkqB > div._1zq6UabIEJJ-z9grsiCJY7 > div:nth-child(2) > div > div > div._2baJGEALPiEMZpWB2iWQs7 > div > div:nth-child(1) > div > div > div').send_keys("Basically what the title says")
#CSS Selector for which community i wanna post it in 
browser.find_element_by_css_selector('#SHORTCUT_FOCUSABLE_DIV > div:nth-child(4) > div > div > div > div._3ozFtOe6WpJEMUtxDOIvtU > div._1vyLCp-v-tE5QvZovwrASa > div._1OVBBWLtHoSPfGCRaPzpTf._3nSp9cdBpqL13CqjdMr2L_._2udhMC-jldHp_EpAuBeSR1.PaJBYLqPf_Gie2aZntVQ7 > div.HOFZo2X7Fr6JVBztpsByj > div.XZK-LTFT5CgGo9MvPQQsy.i0kJNtq5ma1uzbOX9_mM4 > div > div > div.anPJr_ybRailY8NbAunl2 > input').send_keys('r/ibraheem69scitadel'+ Keys.ENTER)
#CSS Selector for the post click button 
browser.find_element_by_css_selector('#SHORTCUT_FOCUSABLE_DIV > div:nth-child(4) > div > div > div > div._3ozFtOe6WpJEMUtxDOIvtU > div._1vyLCp-v-tE5QvZovwrASa > div._1OVBBWLtHoSPfGCRaPzpTf._3nSp9cdBpqL13CqjdMr2L_._2udhMC-jldHp_EpAuBeSR1.PaJBYLqPf_Gie2aZntVQ7 > div.HOFZo2X7Fr6JVBztpsByj > div._3w_665DK_NH7yIsRMuZkqB > div.XZK-LTFT5CgGo9MvPQQsy._1d1--0DMy_jAIxCCoYMo1k > div._2DHDj0dbS1TkKD3fMqSbHy > div > div._1T0P_YQg7fOYLCRoKl_xxO > button').click()
  • Maybe [Handle notifications in Python + Selenium Chrome WebDriver](https://stackoverflow.com/questions/41400934/handle-notifications-in-python-selenium-chrome-webdriver) will help you? – Rashid 'Lee' Ibrahim Sep 01 '20 at 12:45
  • @Rashid'Lee'Ibrahim Can you tell me where I can put this in my code? I have codded this into where i think it should go but then it just gives me a bunch of errors – Poodila Poodia Sep 01 '20 at 12:52

1 Answers1

1

Look into disabling selenium Chrome webdrivers Javascript notifications, like so.

chrome_options = Options()
chrome_options.add_experimental_option( "prefs",{'profile.managed_default_content_settings.javascript': 2})

or as another stackoverflow user has said here

Daniel Saggo
  • 108
  • 1
  • 9
  • Dosent give any errors,although it dosent block the dialouge as well I added the code in such a way that it triggers after chrome starts but before the said website is accessed – Poodila Poodia Sep 01 '20 at 12:59