Selenium Element not visible exception

Solution 1:

If you look at the page source, you'll understand that almost all of theSELECT, DIV elements are faked and created from JavaScript, that is why webdriver cannot SEE them.

There's a workaround though, by using ActionChains to open your developer console, and inject an artificial CLICK on the desired element, which in fact, is the Label triggering the NBA data loading... here's a working example:

from selenium import webdriver
from selenium.webdriver.common import action_chains, keys
import time

driver = webdriver.Firefox()
driver.get('Your URL here...')
assert 'NBA' in driver.page_source
action = action_chains.ActionChains(driver)

# open up the developer console, mine on MAC, yours may be diff key combo
action.send_keys(keys.Keys.COMMAND+keys.Keys.ALT+'i')
action.perform()
time.sleep(3)
# this below ENTER is to rid of the above "i"
action.send_keys(keys.Keys.ENTER)
# inject the JavaScript...
action.send_keys("document.querySelectorAll('label.boxed')[1].click()"+keys.Keys.ENTER)
action.perform()

Alternatively to replace all the ActionChains commands, you can simply run execute_script like this:

driver.execute_script("document.querySelectorAll('label.boxed')[1].click()")

There you go, at least on my local file anyway... Hope this helps!

enter image description here

Solution 2:

What worked for me was to find the element just before the problematic one (that is, just before it in terms of tab order), then call Tab on that element.

from selenium.webdriver.common.keys import Keys
elem = br.find_element_by_name("username")
elem.send_keys(Keys.TAB) # tab over to not-visible element

After doing that, I was able to send actions to the element.

Solution 3:

The actual solution of this thread did not work for me.

however,

this one did :

element  = WebDriverWait(driver, 3).until(EC.visibility_of_element_located((By.XPATH, xpaths['your_xpath_path'])))

the trick is to use :

EC.visibility_of_element_located

the WebDriverWait

WebDriverWait

from this import :

from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.support.ui import WebDriverWait

Solution 4:

I suggest you use xpath with explicit wait

//input[contains(@id,'spsel')][@value='nba']

Solution 5:

if "Element is not currently visible" then make it VISIBLE

f.e.

>>> before is hidden top is outside of page
<input type="file" style="position: absolute;top:-999999" name="file_u">


>>> after move top on in page area
DRIVER.execute_script("document.getElementByName('file_u').style.top = 0;")
time.sleep(1); # give some time to render
DRIVER.find_element_by_name("file_u").send_keys("/tmp/img.png")