I am trying to automate some online activity, but I am stuck at this popup. .
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)
Also, my button is inside this div.
CodePudding user response:
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()
CodePudding user response:
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))