Home > Software design >  Clicking on accept cookies and Continue button on a website using Selenium and Python
Clicking on accept cookies and Continue button on a website using Selenium and Python

Time:02-01

I am trying my best to click the "Allow all" and then the "Continue" button the slido user login website

webiste_link = "https://auth.slido.com/login?auth_state=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IkIifQ.eyJqdGkiOiJkY2MwNThlYy03YjY1LTQxNWQtODJkNS00ZThkOWYxOWZjZDUiLCJjbHVzdGVyX2lkIjoiZXUxIiwiY2xpZW50SWQiOiI2OTFmNGMxNi1kZTM1LTExZWItYmE4MC0wMjQyYWMxMzAwMDQiLCJwcm9tcHQiOiJjb25zZW50IiwicmVkaXJlY3RVcmkiOiJodHRwczovL2FkbWluLnNsaS5kby9vYXV0aC1jYWxsYmFjayIsInNjb3BlIjoib3BlbmlkIG9mZmxpbmVfYWNjZXNzIGVtYWlsIHByb2ZpbGUgc3lzdGVtOnNjb3BlOmFjcXVpcmUiLCJzZXNzaW9uIjp7ImlzQXV0aE4iOmZhbHNlLCJpc0ludGVybmFsIjp0cnVlfSwic3RhdGUiOiJleUp5WldScGNtVmpkQ0k2SW1GSVVqQmpTRTAyVEhrNWFGcEhNWEJpYVRWNllrZHJkVnBIT0haYVdGcHNZbTVTZWlKOSIsImNsYWltcyI6e30sImlhdCI6MTY3NTE4MDk4OCwiZXhwIjoxNjc1MTgyNzg4LCJpc3MiOiJodHRwczovL2F1dGguc2xpZG8uY29tIn0.NvC6eFAmguxI25_Dt8lMsMs4zTquP9DHcz9ukuv1pLzt3kSCVmRYJoTHXuoCpz1SKK6isFdfG8P_0-QHOpXWjdb0Gfxuz50fK5IkaO-vNN84eNQN9rV-Q5Tkw2r6tnyap7Hq3hasiwMoexaBEGx5tTk1y8Ab4xOuXFS0OpeyaiBUjVxr9GsH2TrmuZCdePGverwue_5k-6LStmfjVJlsuh7BC2fkLLNKizbC_mckqLloylu-MChV0GfhXFxHwCpSSRvLa64zmNTZ8KJ1FA3WrNCg5PkjIn6KLdHU7wBmR53MhTE0rMvxOF3gkUoVKerkF5DRe_z9xbRFUW_soAt_5A"

I am trying the following code to do that but it is not working:

chrome_driver_path = user\location\chromedriver.exe"
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(executable_path=chrome_driver_path,options=options)
wait = WebDriverWait(driver, 5)
# open the webpage and enter the email id on the login page
driver.get("webiste_link")
wait.until(EC.element_to_be_clickable((By.ID,"email"))).send_keys("[email protected]")
driver.find_element(By.CLASS_NAME, "//span[text()='Allow all']").click()
time.sleep(5)
#then clicking on the continue button and move forward
driver.find_element(By.CLASS_NAME, "//span[text()='Continue']").click()
time.sleep(5)

But it is not clicking on either of these buttons. Not sure why. What I am doing wrong here?

CodePudding user response:

I think your locator is the issue here. Instead of using ClassName, try XPath

XPath for Accept All button: //button[contains(text(),'Allow all')]

XPath for Continue button: //div[@class='mb8']

  • Related