# Import import time from selenium import webdriver from selenium.webdriver.chrome.options import Options if __name__ == '__main__': # Constructor option = Options() option.add_argument("--disable-infobars") option.add_argument("start-maximized") option.add_argument("--disable-extensions") # Pass the argument 1 to allow and 2 to block option.add_experimental_option("prefs", { "profile.default_content_setting_values.notifications": 1 }) browser = webdriver.Chrome(options=option, executable_path=r"D:\Python\chromedriver.exe") browser.get("https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110") time.sleep(2) browser.execute_script( "if(confirm('Are you sure you want to save this thing into the database?')) {document.getElementById(" "'facebook').appendChild(document.createTextNode('XXYYZZAAABBB'))}") while True: try: time.sleep(3) src = browser.page_source break except Exception as e: browser.execute_script( "if(confirm('Are you sure you want to save this thing into the database?')) {document.getElementById(" "'facebook').appendChild(document.createTextNode('XXYYZZAAABBB'))}") src = browser.page_source is_login_success = False if "XXYYZZAAABBB" in src: is_login_success = True print(is_login_success) time.sleep(1) browser.close()