Skip to content Skip to sidebar Skip to footer

Elementnotvisibleexception: Message: Element Is Not Currently Visible... Selenium (python)

I am getting those annoying element is not visible exception using python's selenium, while the element is active, selected, and flashing. The issue is on the page to make a jfiddl

Solution 1:

JSFiddle editors are powered by CodeMirror which has a programmatic way to set editor values.

For every JSFiddle editor you need to put values into, locate the element with a CodeMirror class, get the CodeMirror object and call setValue():

css_panel = driver.find_element_by_id("panel_css")

code_mirror_element = css_panel.find_element_by_css_selector(".CodeMirror")
driver.execute_script("arguments[0].CodeMirror.setValue(arguments[1]);",
                      code_mirror_element, 
                      "test")

Demo, using JS panel executing the alert("Test"); Javascript code:

>>>from selenium import webdriver>>>>>>driver = webdriver.Firefox()>>>driver.get("https://jsfiddle.net/user/login/")>>>driver.find_element_by_id("id_username").send_keys("user")>>>driver.find_element_by_name("password").send_keys("password")>>>driver.find_element_by_xpath("//input[@value = 'Log in']").click()>>>>>>driver.get("https://jsfiddle.net/")>>>>>>js_panel = driver.find_element_by_id("panel_js")>>>>>>code_mirror_element = js_panel.find_element_by_css_selector(".CodeMirror")>>>driver.execute_script("arguments[0].CodeMirror.setValue(arguments[1]);", code_mirror_element, "alert('test');")>>>>>>driver.find_element_by_id("run").click()>>>

It produces:

enter image description here

Post a Comment for "Elementnotvisibleexception: Message: Element Is Not Currently Visible... Selenium (python)"