0

I am trying to automate some online activity, but I am stuck at this popup. the the facebook cookie acceptance pop up window.

After waiting I am using the XPath: self.driver.find_element_by_xpath('//*[@id="u_0_8_gw"]').click()

But that gives me this exception:

NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="u_0_8_gw"]"}
  (Session info: chrome=96.0.4664.45)

I have also tried using the full path and the id and CSS selector, but none worked. Any suggestions?

Update: HTML code (cannot add as text)

HTML code

Also, my button is inside this div. div

  • Is the popup in an iframe? See https://stackoverflow.com/questions/18924146/selenium-and-iframe-in-html – Taco Verhagen Nov 25 '21 at 22:27
  • Checked based on [this](https://www.geeksforgeeks.org/how-to-check-a-webpage-is-loaded-inside-an-iframe-or-into-the-browser-window-using-javascript/), and it is not in an iframe. – Szèles Àron Nov 25 '21 at 22:48
  • @SzèlesÀron There can be multiple reasons of not working because you have not provided the DOM? please share the html. It can be an alert, it can be inside shadow root, might be the locator is not correct etc. So please share the DOM or share the URL. – QualityMatters Nov 26 '21 at 06:54
  • @QualityMatters added HTML – Szèles Àron Nov 26 '21 at 08:52
  • Your locator does not look correct. Can you check with this in your dom? Is it highlighting your element? //button[@data-testid='cookie-policy-dialog-accept-button'] – QualityMatters Nov 26 '21 at 09:19
  • @QualityMatters no it does not highlight it. – Szèles Àron Nov 26 '21 at 13:20
  • @SzèlesÀron Can you share the url, how you are reaching there? – QualityMatters Nov 26 '21 at 13:21
  • @QualityMatters I am being directed to the shown popup after clicking on "login with Facebook", so you would not be able to access the link. – Szèles Àron Nov 26 '21 at 14:20

2 Answers2

0

You need to direct the webdriver to the pop-up window. If you can provide the pop window HTML code. I can show you how to direct the webdriver to the particular window. Also, Once you finish interesting the pop-up you need to direct the webdriver to the main window.

The pop-up window looks like an iFrame. If it's an iframe you need to direct webdriver as follow: If the iframe has an ID execute bellow command

    driver.switchTo().frame("<iframeId>"); 
    //afterwards execute your click event
    self.driver.find_element_by_xpath('//*[@id="u_0_8_gw"]').click()
Ramitha Silva
  • 130
  • 2
  • 5
  • 18
0

If NoSuchElementException accrued and xpath is right then the scroll to target button :

driver.execute_script('arguments[0].scrollIntoView(true);', 
        driver.find_element_by_xpath(XPATH OF Target button))
jainam shah
  • 149
  • 9