1

I have been trying to automate facebook searching using python selenium but I don't know how to allow or block the pop ups, I have provided a picture below, that might help you understand the problem better

https://i.stack.imgur.com/V1ABR.png

This is the code, and I don't know what I have imported but it still works though :-)

import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

driver = webdriver.Chrome()

facebook_URL = ('https://www.facebook.com/')
twitter_URL = ('https://www.twitter.com/')


def facebook():
    driver.get(facebook_URL)  # To open the browser and search for facebook
    time.sleep(2)

    # It finds the Input box for the email
    emailFace = driver.find_element_by_xpath('//*[@id="email"]')
    # This inputs the the text which we want to
    emailFace.send_keys('hello@gmail.com')

    passFace = driver.find_element_by_xpath('//*[@id="pass"]')
    passFace.send_keys('check1234')

    loginFace = driver.find_element_by_xpath('//*[@id="u_0_b"]')
    loginFace.click()


def twitter():
    driver.get(twitter_URL)  # To open the browser and search for facebook
    time.sleep(2)

    logIn = driver.find_element_by_xpath(
        '//*[@id="react-root"]/div/div/div/main/div/div/div/div[1]/div/a[2]')
    logIn.click()

    # It finds the Input box for the email
    emailTwitt = driver.find_element_by_xpath(
        '//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[1]/label/div/div[2]/div/input')
    # This inputs the the text which we want to
    emailTwitt.send_keys('hello@gmail.com')

    passTwitt = driver.find_element_by_xpath(
        '//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[2]/label/div/div[2]/div/input')
    passTwitt.send_keys('check1234')

    loginTwitt = driver.find_element_by_xpath(
        '//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[3]/div')
    loginTwitt.click()


facebook()
Aarnav
  • 11
  • 3

1 Answers1

0

From This Topic i assume you can take alike the last few lines of code and paste it to your script. Be careful that the Text on the Button isnt the same for firefox and chrome though, so you have to adjust that. The code to add might look like this:

    #this for the "safe password information button
    save_login_info_button= browser.find_element_by_xpath("//button[text()='Never']")
    save_login_info_button.click()
    sleep(3)
    #this for the notification button 
    notification_button= browser.find_element_by_xpath("//button[text()='Block']")
    notification_button.click()
Timeler
  • 377
  • 1
  • 11