Selenium Element not visible exception

1
0

I have been tasked with writing a parser to click a button on a website and I am having issues to click only one of the buttons. The following code works on every button except one.

Here’s the html:
http://pastebin.com/6dLF5ru8

here’s the source html:
http://pastebin.com/XhsedGLb

python code:

 driver = webdriver.Firefox()  
...
el
= driver.find_element_by_id("-spel-nba")
actions
.move_to_element(el)
actions
.sleep(.1)
actions
.click()
actions
.perform()

I am getting this error.

ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with

as per Saifur I just tried waits with the same element not visible exception:

wait = WebDriverWait(driver, 10)
wait
.until(EC.presence_of_element_located((By.XPATH, "//input[contains(@id,'spsel')][@value='nba']"))).click()
  • You must to post comments
0
0

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

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website