我有一个这样的页面:
<div class="CodeMirror">
<div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 6.2px; left: 182.2px;">
<textarea autocapitalize="off" autocorrect="off" style="position: absolute; padding: 0px; width: 1px; height: 1em;" wrap="off"></textarea>
</div>
<div style="display: none; height: 106px;" class="CodeMirror-scrollbar"> <div style="height: 114px;" class="CodeMirror-scrollbar-inner"></div></div>
<div> ...
...
..
</div>
<pre style="top: 39px; left: 0px;" class="CodeMirror-cursor"> </pre>
<div style="">
<pre>asdf</pre>
<pre>asdfasdf</pre> It's weird the textarea content is here
<pre>asdfasdf</pre>
<pre> </pre>
</div>
...
...
我使用selenium进行选择,但获取了两个元素,并向其中一个元素发送密钥,它抛出了Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with
下面是我的操作命令:
browser.browser.public_send(:textareas, :xpath => "//div[@class='CodeMirror']//textarea[@wrap='off']" )[0].html
=> "<textarea autocapitalize=\"off\" autocorrect=\"off\" style=\"position: absolute; padding: 0px; width: 1px; height: 1em;\" wrap=\"off\"></textarea>"
[58] pry(#<CucuShift::DefaultWorld>)> browser.browser.public_send(:textareas, :xpath => "//div[@class='CodeMirror']//textarea[@wrap='off']" )[1].html
=> "<textarea autocapitalize=\"off\" autocorrect=\"off\" style=\"position: absolute; padding: 0px; width: 1px; height: 1em;\" wrap=\"off\"></textarea>"
browser.browser.public_send(:textareas, :xpath => "//div[@class='CodeMirror']/descendant::textarea[@autocorrect='off']" )[1].click
Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with
from [remote server] file:///tmp/webdriver-profile20160801-26332-bu7605/extensions/fxdriver@googlecode.com/components/command-processor.js:10092:in `fxdriver.preconditions.visible'
browser.browser.public_send(:textareas, :xpath => "//div[@class='CodeMirror']/descendant::textarea[@autocorrect='off']" )[1].send_keys '1234'
Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with
from [remote server] file:///tmp/webdriver-profile20160801-26332-bu7605/extensions/fxdriver@googlecode.com/components/command-processor.js:10092:in `fxdriver.preconditions.visible'
最奇怪的是这些元素html都是一样的。
发布于 2016-08-01 10:41:43
你不能访问文本区域的原因是你的文本区域的父div有"overflow: hidden“属性。因此,你的文本区域是不可见的。如果从代码中删除"overflow:hidden“属性,文本区域将可见,您将能够使用Selenium -and手动访问它。
审查者注意:事实上,问题本身并不是那么清楚。我试着根据标题来回答这个问题:用户想要与web元素交互,而我的答案提供了一个解决方案。
https://stackoverflow.com/questions/38694102
复制相似问题