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!

kvdesai2
  • 75
  • 1
  • 7
  • Please add the full traceback. What object is not callable? [mcve] – Håken Lid Jun 30 '17 at 21:56
  • I am getting that the 'localfiledetector' object is not callable. I currently have "detector" as the input for driver.file_detector() – kvdesai2 Jul 03 '17 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. https://stackoverflow.com/a/10472542/1977847 – Håken Lid Jul 03 '17 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. – kvdesai2 Jul 03 '17 at 13:58

1 Answers1

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.

Håken Lid
  • 22,318
  • 9
  • 52
  • 67