如何在 selenium 中关闭 Shopee 弹出窗口

How to close Shopee pop up in selenium

我想在 selenium 中关闭站点 https://shopee.com.my/ 的弹出窗口 请检查下图。

我在下面尝试过,但出现类似

的错误
NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":".shopee-popup__close-btn"}

代码:

driver.find_element_by_class_name("shopee-popup__close-btn").click()

它在影子根中。

代码:

driver_path = r'C:\Users\***\***\chromedriver.exe'

driver = webdriver.Chrome(driver_path)

driver.maximize_window()
wait = WebDriverWait(driver, 30)

driver.get("https://shopee.com.my/")

wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='English']"))).click()

try:
   time.sleep(3)
   close_btn = driver.execute_script('return document.querySelector("#main shopee-banner-popup-stateful").shadowRoot.querySelector("div.home-popup__close-area div.shopee-popup__close-btn")')
   close_btn.click()
   print('Clicked successfully')
except:
   print('Could not clicked')
   pass

进口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC