我正在尝试使用 python 进行网页抓取,但发现错误
JavascriptException:javascript错误:无法读取 null 的属性(读取“shadowRoot”)
我不明白如何解决它。 请指导我。预先感谢您
这是我的代码:
from selenium import webdriver
option = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = option)
#Open Shopee website
driver.get('https://www.shopee.co.th/')
#Click TH link
th_button = driver.find_element("xpath",'/html/body/div[2]/div[1]/div[1]/div/div[3]/div[1]/button')
th_button.click()
driver.execute_script('return document.querySelector("shopee-banner-popup-stateful").shadowRoot.querySelector("div.shopee-popup__close-btn")')
我想从这段代码中关闭弹出窗口
检查下面的工作代码:
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://www.shopee.co.th/")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='ไทย']"))).click()
time.sleep(10)