【问题标题】:notification pop up python selenium [duplicate]通知弹出python selenium [重复]
【发布时间】:2020-11-29 13:04:21
【问题描述】:

我一直在尝试使用 python selenium 自动化 facebook 搜索,但我不知道如何允许或阻止弹出窗口,我在下面提供了一张图片,这可能有助于您更好地理解问题

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

这是代码,我不知道我导入了什么,但它仍然有效:-)

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()

【问题讨论】:

  • 真的有用吗?
  • 我还没试过,如果有效我会告诉你谢谢!

标签: python selenium selenium-webdriver


【解决方案1】:

来自This 主题我假设您可以将最后几行代码粘贴到您的脚本中。请注意,按钮上的文本与 firefox 和 chrome 不同,因此您必须对其进行调整。 要添加的代码可能如下所示:

    #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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 2021-03-12
    相关资源
    最近更新 更多