点击“不立即" Instagram上的通知使用Selenium和Python询问 [英] Click ''Not now" on Instagram notifications ask using Selenium and Python
问题描述
我编写了一个脚本,可以成功在Instagram上进行登录. 当我应该在家中使用帐户时,该网站会显示一个弹出窗口,询问您是否要发送通知. 在这一点上,我尝试了很多解决方案,但一无所获. 我只想在显示弹出窗口时,脚本应单击不立即".
I've written a script that successfully makes the login on Instagram. When I should go on my account, at home, the website displays a popup that asks you if you want notifications. At this point, I tried a lot of solutions, but I got nothing. I just want that, when the pop-up is displayed, the script should click on "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 ')]")
在图像中,我要单击的突出显示的按钮行:
In the image, there's the line of the button highlighted that I want to click:
推荐答案
为此尝试以下代码:
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秒钟的等待时间才能单击该元素.
PS: I have used 10-second wait for the element to be clickable before click on it.
希望它对您有帮助!
这篇关于点击“不立即" Instagram上的通知使用Selenium和Python询问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!