2

I am using Selenium in Python to create an automated test. In this test, I am trying to select a file from a local directory. I was able to find a reference using Java but I am struggling to convert this to Python. https://sqa.stackexchange.com/questions/12851/how-can-i-work-with-file-uploads-during-a-webdriver-test

    element=driver.find_element_by_id("file_browse").click()
    driver.file_detector("<>")
    upload=driver.find_element_by_id("<>")
    keys=upload.send_keys("<>")

For the file detector function I keep getting that the object is not callable. What should the input be for it?

Thanks!

4
  • Please add the full traceback. What object is not callable? minimal reproducible example Commented Jun 30, 2017 at 21:56
  • I am getting that the 'localfiledetector' object is not callable. I currently have "detector" as the input for driver.file_detector() Commented Jul 3, 2017 at 11:53
  • What do you expect driver.file_detector() to do? I'm not familiar with the api, but it appears to be a class instance that is not callable. Are you sure that what you want to do requires the use of a "file detector"? Take a look at this answer. stackoverflow.com/a/10472542/1977847 Commented Jul 3, 2017 at 12:08
  • I'm not sure what it exactly does, but I think it would allow me to select the file. I saw it in the link for the Java example and tried to implement that. Commented Jul 3, 2017 at 13:58

1 Answer 1

2

Just remove this line:

driver.file_detector("<>")

Python's remote webdriver uses LocalFileDetector() by default. That seems to be what you want, looking at the linked Java example.

If you need to override the default, you can use or subclass one of the available file detectors from selenium.webdriver.remote.file_detector

There doesn't seem to be any documentation of how to use FileDetector, but the source code is quite short and straightforward.

from selenium.webdriver.remote.file_detector import UselessFileDetector

driver.file_detector = UselessFileDetector()

Python's ideom for setting object members is simply to use the assignment operator (=) instead of calling a set method, as you would in Java.

Sign up to request clarification or add additional context in comments.

Comments

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.