-1

I am aware there have been similar questions, however the answers to the others do not seem to fix my issue.

I am able to open youtube and dismiss the sign-in pop-up, however I cannot seem to agree to cookies for the google pop-up. The reason why I am posting a similar question is because the common "driver.implicitly_wait(10)" solution only seems to work on the sign-in pop-up.

This suggests for some reason the xpath for the button only works for the youtube pop-up, and not the google pop-up.

My code:

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver=webdriver.Chrome(executable_path="C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")

driver.implicitly_wait(10)
driver.get("https://www.youtube.com/watch?v=nYh-n7EOtMA")
driver.find_element_by_xpath("//*[@id='dismiss-button']").click()
driver.implicitly_wait(10)
driver.find_element_by_xpath("//*[@id='introAgreeButton']").click()

I also believe that this is also the correct piece of code to copy the xpath of the button from.

Picture of HTML code

I would be really grateful for any potential solutions, and I'm really sorry if this is too similar to previous questions, I'm just really stumped.

Aloof
  • 13
  • 3

1 Answers1

0
driver.switch_to.frame("iframe")
driver.find_element_by_xpath("//*[@id='introAgreeButton']").click()

The agree button is inside an iframe just switch to it first, as you are using implict wait you don't have to use anyother waits

now if you want to interact with any element outside the iframe use:

driver.switch_to.default_content()

Before trying to find or interact with that element

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • I am really thankful to you and the person who commented on my post, it worked and I learned that iframes exist :D. Thanks and have a great day :). – Aloof Feb 02 '21 at 17:18