单击 Instagram 通知上的“不是现在”询问使用 Selenium 和 Python
Click ''Not now" on Instagram notifications ask using Selenium and Python
我写了一个脚本,可以成功登录 Instagram。
当我应该在家里使用我的帐户时,该网站会显示一个弹出窗口,询问您是否需要通知。
在这一点上,我尝试了很多解决方案,但我一无所获。
我只是希望,当显示 pop-up 时,脚本应该单击 "Not now"。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
ids = []
driver = webdriver.Chrome(executable_path = '/usr/local/bin/chromedriver')
driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
usm = driver.find_element_by_name('username').send_keys("**")
pwd = driver.find_element_by_name('password').send_keys("**")
btnLog = driver.find_element_by_tag_name('form').submit()
acpt = driver.find_element_by_xpath("//*[contains(@class, 'aOOlW HoLwm ')]")
在图片中,突出显示了我要单击的按钮行:
为此尝试以下代码:
from selenium.webdriver.support import ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
ui.WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".aOOlW.HoLwm"))).click()
PS:我已经使用了 10 秒等待元素可点击,然后再点击它。
希望对您有所帮助!
To click()
在 Not now 在 Instagram 弹出通知的元素上,您可以使用以下解决方案:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
options = Options()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
driver.find_element_by_name('username').send_keys("Giacomo")
driver.find_element_by_name('password').send_keys("Maraglino")
driver.find_element_by_tag_name('form').submit()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(.,'Non ora')]"))).click()
只需添加点击即可接受,如下所示:
acpt = driver.find_element_by_xpath("//*[contains(@class, 'aOOlW HoLwm ')]")
acpt.click()
我写了一个脚本,可以成功登录 Instagram。 当我应该在家里使用我的帐户时,该网站会显示一个弹出窗口,询问您是否需要通知。 在这一点上,我尝试了很多解决方案,但我一无所获。 我只是希望,当显示 pop-up 时,脚本应该单击 "Not now"。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
ids = []
driver = webdriver.Chrome(executable_path = '/usr/local/bin/chromedriver')
driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
usm = driver.find_element_by_name('username').send_keys("**")
pwd = driver.find_element_by_name('password').send_keys("**")
btnLog = driver.find_element_by_tag_name('form').submit()
acpt = driver.find_element_by_xpath("//*[contains(@class, 'aOOlW HoLwm ')]")
在图片中,突出显示了我要单击的按钮行:
为此尝试以下代码:
from selenium.webdriver.support import ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
ui.WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".aOOlW.HoLwm"))).click()
PS:我已经使用了 10 秒等待元素可点击,然后再点击它。
希望对您有所帮助!
To click()
在 Not now 在 Instagram 弹出通知的元素上,您可以使用以下解决方案:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
options = Options()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
driver.find_element_by_name('username').send_keys("Giacomo")
driver.find_element_by_name('password').send_keys("Maraglino")
driver.find_element_by_tag_name('form').submit()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(.,'Non ora')]"))).click()
只需添加点击即可接受,如下所示:
acpt = driver.find_element_by_xpath("//*[contains(@class, 'aOOlW HoLwm ')]")
acpt.click()