Python/Selenium-无法单击';接受cookies';www.instagram.com上的按钮
我正在尝试使用python selenium登录instagram。但我必须接受这些饼干才能继续 这是我的密码Python/Selenium-无法单击';接受cookies';www.instagram.com上的按钮,python,selenium,cookies,selenium-chromedriver,Python,Selenium,Cookies,Selenium Chromedriver,我正在尝试使用python selenium登录instagram。但我必须接受这些饼干才能继续 这是我的密码 class InstaBot: def __init__(self, username, pw): self.driver = webdriver.Chrome() self.driver.get('https://www.instagram.com/') sleep(2) #this is the code that im
class InstaBot:
def __init__(self, username, pw):
self.driver = webdriver.Chrome()
self.driver.get('https://www.instagram.com/')
sleep(2)
#this is the code that im trying to use, so to click the accept button
self.driver.find_element_by_xpath("/html/body/div[2]/div/div/div/div[2]/button[1]").click()
self.driver.find_element_by_xpath("//input[@name=\"username\"]")\
.send_keys(username)
self.driver.find_element_by_xpath("//input[@name=\"password\"]")\
.send_keys(pw)
self.driver.find_element_by_xpath("//a[contains(text(), 'Log in')]")\
.click()
sleep(4)
问题是,当它点击accept按钮时,它什么也不做。有什么想法吗?应该单击“接受登录”按钮,然后单击后面的两个元素。只需等待元素变得可单击,然后单击它
WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Accept']"))).click()
#Your code
WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#loginForm > div > div:nth-child(3) > button"))).click()
WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Save Info']"))).click()
WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Turn On']"))).click()
进口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
尝试使用以下方法:
self.driver.find_element_by_xpath("//button[text()='Accept']").click()
我在这里发布了我的解决方案: