我需要找到“上传”按钮,并输入上传视频。下面是标记的元素和我的代码。Input fieldUpload button
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
def test():
driver = webdriver.Firefox()
upload_url = "https://www.tiktok.com/upload?lang=en-EN"
login_url = "https://www.tiktok.com/login"
print("Log in manually and press ENTER", end = '')
time.sleep(5)
driver.get(login_url)
driver.implicitly_wait(10)
input()
print("Loading upload page...")
driver.get(upload_url)
driver.implicitly_wait(10)
path = ".../yt_to_tt_uploader/yt_videos/YMbO9YYzvVw.mp4"
upload = driver.find_element(By.XPATH, "//input[@type='file']")
upload.send_keys(path)
upload_button = driver.find_element(By.XPATH, "//button[class='css-y1m958']")
upload_button.click()
这是引发错误
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //input[@type = 'file']
我试着通过XPATH,CLASS_NAME,文本找到它,但也许我错了,我需要在字段中上传视频并点击“上传”
1条答案
按热度按时间7rtdyuoh1#
Selenium无法在您的代码中找到此元素
//input[@type='file']
。请尝试使用显式等待,看看它是否有效,下面的代码供您参考:如果使用
presence_of_element_located
不起作用,那么尝试visibility_of_element_located
。需要导入语句:
我发现另一个XPath中还有一个问题,缺少
@
:从
//button[class='css-y1m958']
变更为//button[@class='css-y1m958']