Courtesy of this answer I've got this bit of Selenium working:
import contextlib
from selenium import webdriver
with contextlib.closing(webdriver.Chrome()) as driver:
driver.get("http://www.bing.com/images")
driver.find_element_by_id("sbi_t").click()
element = driver.find_element_by_id("sbi_file_upload")
element.send_keys("//Loch Ness Monster.jpg")
However, when I switch from webdriver.Chrome()
to webdriver.Firefox()
, I start getting selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
. My guess is that the error is related to the magic that Selenium performs to work with operating system file upload selector dialogs. I would think that's probably also why my attempts to wait until the element becomes visible aren't working: the "magic" does not involve the element ever becoming visible. Here's what I tried:
# https://stackoverflow.com/a/15142611/2829764, found via https://stackoverflow.com/q/6101461/2829764
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
...
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "sbi_file_upload")))
I'm using Firefox 36.0.1, Selenium 2.45.0, and Python 2.7.9. Incidentally, Selenium had stopped working with Firefox when I updated Firefox to 36.0.1 but I updated my Selenium today and the particular problem I was having went away.