Code used in VISUAL STUDIO CODE:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.google.co.in/")
driver.maximize_window()
time.sleep(3)
driver.find_element(By.XPATH,"/html/body/div/c-wiz/div/div/c-wiz/div/div/div/div[2]/div[2]/button").click()
enter image description hereError getting
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/c-wiz/div/div/c-wiz/div/div/div/div[2]/div[2]/button"}
(Session info: chrome=108.0.5359.125)
Stacktrace:
Backtrace:
(No symbol) [0x005AF243]
(No symbol) [0x00537FD1]
(No symbol) [0x0042D04D]
(No symbol) [0x0045C0B0]
(No symbol) [0x0045C22B]
2
Answers
Those elements are in an iframe, so you need to switch to the frame first, and then click a button in there:
I can’t see "No Thanks" on that page, but the "Login" button can be accesed there as following:
I used XPath here. However this can be done with CSS Selectors as well