2016-08-01 3 views
0

У меня есть страница, как это:Селен Элемент в настоящее время не видно и поэтому не может быть взаимодействовали с

<div class="CodeMirror"> 
 
<div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 6.2px; left: 182.2px;"> 
 
\t <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">&nbsp;</pre> 
 
<div style=""> 
 
<pre>asdf</pre> 
 
<pre>asdfasdf</pre> It's weird the textarea content is here 
 
<pre>asdfasdf</pre> 
 
<pre> </pre> 
 
</div> 
 
... 
 
...

и я использую селен, чтобы выбрать, но получить два элемента и я посылаю ключ к одной из них бросает 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/[email protected]/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/[email protected]/components/command-processor.js:10092:in `fxdriver.preconditions.visible'

самая странная вещь есть те тоже элементы HTML одинаковы.

ответ

0

Причина, по которой вы не можете получить доступ к текстовому пространству, состоит в том, что родительский div вашего текстового поля имеет атрибут «переполнение: скрытый». Следовательно, ваше текстовое пространство невидимо. Если вы удалите атрибут «переполнение: скрытый» из вашего кода, текстовое поле будет видимым, и вы сможете получить к нему доступ с помощью Selenium и вручную.

Примечание для рецензентов: на самом деле вопрос не так ясен. Я попытался ответить на него, опираясь на заголовок: пользователь хочет взаимодействовать с веб-элементом, и мой ответ дает решение.

+0

На самом деле, это проблема CodeMirror –

Смежные вопросы

 Смежные вопросы