Madar
Madar

Reputation: 247

Python selenium invalid argument?

So, I'm trying to use selenium with my new computer on ubuntu, but I'm having this problem and I really don't know what I can do to solve it.

Here is the code :

    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)

Here is the traceback :

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

I tried changing \ into / but doesn't work either. If someone has an idea, I'm listening!

Upvotes: 0

Views: 218

Answers (1)

PDHide
PDHide

Reputation: 19939

The stack trace is self exploratory :

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

make sure this file and path exist

Use:

send_keys(os.path.abspath(file))

Upvotes: 1

Related Questions