0

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!

2
  • What is the absolute path of the file? What is the value of absolute_way? Commented Jan 7, 2021 at 10:18
  • @DebanjanB "home\\pierre\\Documents\\python_projet\\Program_r\\Video\\over\\", it's on the second python line of the traceback Commented Jan 7, 2021 at 10:21

1 Answer 1

1

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))
Sign up to request clarification or add additional context in comments.

2 Comments

I know, and this path exist, cause the file come from the os.listdir function. But I don't know why selenium don't want to find / see the file is here
@Madar use send_keys(os.path.abspath(file))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.