Python 2.7 消息:元素不可见

Python 2.7 消息:元素不可见,python-2.7,selenium-webdriver,Python 2.7,Selenium Webdriver,在使用Python 2.7上的selenium的页面上使用send_键时遇到一些问题。可以与页面中的其他元素交互,但不能与此元素交互: <div id="request"><textarea id="content" style="display: none;"></textarea><div class="CodeMirror cm-s-default"><div style="overflow: hidden; position: rel

在使用Python 2.7上的selenium的页面上使用send_键时遇到一些问题。可以与页面中的其他元素交互,但不能与此元素交互:

<div id="request"><textarea id="content" style="display: none;"></textarea><div class="CodeMirror cm-s-default"><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 6px; left: 5px;"><textarea autocorrect="off" autocapitalize="off" style="position: absolute; padding: 0px; width: 1000px; height: 1em; outline: none;" tabindex="0"></textarea></div><div class="CodeMirror-hscrollbar" style="left: 0px;"><div style="height: 1px;"></div></div><div class="CodeMirror-vscrollbar"><div style="width: 1px;"></div></div><div class="CodeMirror-scrollbar-filler"></div><div class="CodeMirror-scroll" tabindex="-1" draggable="false"><div style="position: relative; min-height: 100%;"><div class="CodeMirror-sizer" style="min-width: 44.7969px; margin-left: 0px; min-height: 25px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines"><div style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>&nbsp;</span></pre></div><div style="position: relative; z-index: 1; display: none;"><div class="CodeMirror-selected" style="position: absolute; left: 4px; top: 1px; width: 46.7812px; height: 15px;"></div></div><div style=""><pre>&nbsp;</pre><pre style="display: none;">ffffff</pre></div><div class="CodeMirror-cursor" style="left: 4px; top: 1px; height: 15px; visibility: hidden;">&nbsp;</div><div class="CodeMirror-cursor CodeMirror-secondarycursor" style="display: none; visibility: hidden;">&nbsp;</div></div></div></div></div><div style="position: absolute; height: 30px; top: 25px;">&nbsp;</div><div class="CodeMirror-gutters" style="display: none;"></div></div></div></div></div>

但它们都触发ElementNotVisibleException

使用操作链解决:

driver.find_element_by_id('content').click().send_keys("Hello World!")

driver.find_element_by_xpath('//*[@id="ad-request"]/div/div[5]/div/div[1]/div/div/div/div[3]/pre').send_keys("Hello World!")
action.send_keys(keys.Keys.COMMAND+keys.Keys.ALT+'')
action.perform()
time.sleep(3)
action.send_keys("content"+keys.Keys.ENTER)
action.perform()