2

I am writing some code automation code and whenever I create a new tab and go on "google.com" and get a cookies pop up message which I cannot automate. I was wondering if anyone had any solution on how to overcome this?

KunLun
  • 3,109
  • 3
  • 18
  • 65
Emmanuel
  • 31
  • 4
  • I don't know the python but I can try to help you. That pop-up is an `iframe`. 1. switch the `driver` to `iframe` (xpath: `//iframe[contains(@src, 'consent.google.com')]`). 2. click `I agree` (xpath: `//form //div[@role = 'button' and @id = 'introAgreeButton']`). 3. switch `driver` to default content. And that's it. But first of all, Check if `iframe` is present. If not, skip the part with `switch and agree` – KunLun Nov 15 '20 at 16:52
  • 1
    Thanks for your help I fixed it using driver.switch_to.frame(driver.find_element_by_xpath("//iframe[contains(@src, 'consent.google.com')]")) time.sleep(5) driver.find_element_by_xpath('//*[@id="introAgreeButton"]/span/span').click() – Emmanuel Nov 15 '20 at 20:24
  • Hey @KunLun, I executed an open window script on my automation and on the new web page I am having trouble locating any of the elements and keep getting the error `SyntaxError: Failed to execute 'evaluate' on 'Document''`. After executing my google script I changed the driver to the default content using `driver.switch_to.default_content()` – Emmanuel Nov 16 '20 at 17:23
  • Can you show me what code you try to execute after switch to default? First try to read this: https://stackoverflow.com/questions/52069778/syntaxerror-failed-to-execute-evaluate-on-document-the-string-imgconta – KunLun Nov 16 '20 at 17:32
  • 'driver.switch_to.default_content() driver.execute_script("window.open('https://www.linkedin.com/login');") time.sleep(2) driver.find_element_by_xpath('//*[@id="app__container"]/main/div[3]/form/div[1]/label').send_keys(elementPaths.emailUsername) driver.find_element_by_id('password').send_keys(elementPaths.emailPassword) nextButton = driver.find_element_by_class_name('sign-in-form__submit-button').click() ' This is the code I ran after doing my google search, I am trying to login to LinkedIn @KunLun – Emmanuel Nov 16 '20 at 17:40
  • I apologise for the formatting @KunLun , I am new to posting on stack overflow – Emmanuel Nov 16 '20 at 17:41
  • There is no problem. But in the future open a new question for a different problem. When you open a new window: `driver.execute_script("window.open('linkedin.com/login');")`, you also need to switch the driver to that window, because it not switch automatically. Read here about it: https://stackoverflow.com/questions/10629815/how-to-switch-to-new-window-in-selenium-for-python and https://www.tutorialspoint.com/how-to-open-a-new-window-on-a-browser-using-selenium-webdriver-for-python – KunLun Nov 16 '20 at 17:55

0 Answers0