我想在 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()
uj5u.com熱心網友回復:
它在影子根中。
代碼:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/451811.html
標籤:python-3.x 硒 硒网络驱动程序
