kvdesai2
kvdesai2

Reputation: 75

Selecting a local file with Selenium Automated testing

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!

Upvotes: 2

Views: 4454

Answers (1)

H&#229;ken Lid
H&#229;ken Lid

Reputation: 23064

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.

Upvotes: 2

Related Questions