1 回答

TA貢獻1862條經驗 獲得超7個贊
您之后的元素位于內部,iframe您需要先切換到 iframe 才能訪問該元素。
Induce WebDriverWait() 和 wait for frame_to_be_available_and_switch_to_it() 以及跟隨的 css 選擇器。
歸納WebDriverWait()并等待element_to_be_clickable()
browser.get('https://www.tiktok.com/foryou?lang=ru')
#Click on Login
WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"a.jsx-3665539393"))).click()
#Click cookeis button
WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.button-wrapper>button"))).click()
WebDriverWait(browser,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src*='tiktok']")))
browser.execute_script("arguments[0].click();",WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.close-modal-8dfIo"))))
您需要導入以下庫
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
添加回答
舉報