ElementNotVisibleException: Message: element is not currently visible ... selenium (python)

I get that this annoying element is not a visible exception using python selenium, while the element is active, selected and blinking.

The problem is to make jfiddle, so instead of making the violin of the violin itself, here we cut out and paste the login method and have webdriver (named 'driver') in your ipython terminal (enter the username and password in ipython, not a page):

https://gist.github.com/codyc4321/787dd6f62e71cc71ae83

Now there is a driver, and you are logged into jsfiddle, everything I do here fails, except for selecting the box for the first time (let's say I want to reset the CSS in the CSS field):

https://gist.github.com/codyc4321/f4c03c0606c2e3e4ff5b

Insert activate_hidden_element , and the first code line and see the CSS panel will light up. For some reason, this highlighted panel is "not visible" and you cannot embed and encode it. Element

  <div class="window top" id="panel_css" data-panel_type="css"> <textarea id="id_code_css" rows="10" cols="40" name="code_css"></textarea> <a href="#" class="windowLabel" data-panel="css"> <span class="label">CSS</span><i class="bts bt-gear"></i> </a> </div> 

All other elements (HTML, JS) are essentially the same. Why cannot text be inserted in this active field? Thanks you

DECISION:

The ugly way that I did this job was to manually cut and paste the fake:

 css_content = get_inline_content_and_remove_tags(webpage_content, 'style') js_content = get_inline_content_and_remove_tags(webpage_content, 'script') webpage_content = # ...clean cruft... def copy_paste_to_hidden_element(content=None, html_id=None): pyperclip.copy(content) activate_hidden_element(html_id=html_id, driver=driver) call_sp('xdotool key from+ctrl+v') time.sleep(1) copy_paste_to_hidden_element(content=webpage_content, html_id="panel_html") copy_paste_to_hidden_element(content=js_content, html_id="panel_js") copy_paste_to_hidden_element(content=css_content, html_id="panel_css") 

It works, the only minor problem is that it cannot work in the background, I need to leave the screen alone for 30 seconds

+8
javascript python selenium selenium-webdriver
source share
1 answer

JSFiddle editors are powered by CodeMirror , which has a programmatic way of setting editor values.

For each JSFiddle editor you need to enter values, find an element with the CodeMirror class, get a 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 alert("Test"); code alert("Test"); Javascript:

 >>> 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

+9
source share

All Articles