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
添加回答
举报