首页 > 解决方案 > Python硒无效参数?

问题描述

所以,我试图在 ubuntu 上将 selenium 与我的新计算机一起使用,但我遇到了这个问题,我真的不知道我能做些什么来解决它。

这是代码:

    driver = webdriver.Firefox(executable_path='./geckodriver') # launch firefox 
    driver.get("https://www.tiktok.com/@programm___r?lang=en") # go to the website 
    WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CLASS_NAME,"jsx-2482409767.upload-wrapper"))).click() # click on an element 
    files = os.listdir(folder_name) # Get all the file of the folder "folder_name"
        exts = ["mp4","mov"] # just the extension to pick only the file I want 
        for file in files: 
            if file.split(".")[-1] in exts: # Select only the file I want 
               WebDriverWait(driver,20).until(EC.presence_of_element_located((By.CLASS_NAME,class_name))) # wait for an element to appear 
               driver.find_element_by_class_name(class_name).send_keys(folder_name+"\\"+file) # I'm trying to send the file the for just picked 
               # but this is what cause the error
               # I also tried with the absolute way but it didn't work neither
               driver.find_element_by_class_name(class_name).send_keys(absolute_way+"\\"+file)

这是回溯:

Traceback (most recent call last):
  File "auto_post.py", line 167, in <module>
    ordi_post("./Video/over","Firefox","linux","programmer")
  File "auto_post.py", line 142, in ordi_post
    wait_send("jsx-1828163283.upload-btn-input",r"home\\pierre\\Documents\\python_projet\\Program_r\\Video\\over\\"+file)
  File "auto_post.py", line 122, in wait_send
    driver.find_element_by_class_name(class_name).send_keys(send_file)
  File "/home/pierre/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 477, in send_keys
    self._execute(Command.SEND_KEYS_TO_ELEMENT,
  File "/home/pierre/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/home/pierre/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pierre/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: File not found: home\\pierre\\Documents\\python_projet\\Program_r\\Video\\over\\Treecko.mp4

我尝试将 \ 更改为 / 但也不起作用。如果有人有想法,我在听!

标签: pythonseleniumselenium-webdriver

解决方案


堆栈跟踪是自我探索的:

File not found: home\\pierre\\Documents\\python_projet\\Program_r\\Video\\over\\Treecko.mp4

确保此文件和路径存在

采用:

send_keys(os.path.abspath(file))

推荐阅读