浏览器显示文本但在HTML代码中找不到该文本

3
我需要使用Selenium捕获文本区域元素内的文本。这意味着要捕获信息,我必须请求HTML元素内的属性。
请查看图片。

enter image description here

问题出在“Codigo Servicio”标签旁的<textarea>元素上。文本“VPF987654321”明显存在于该元素中,但是该元素没有显示任何文本(请查看检查器中的高亮代码)。我在检查器中搜索文本,但没有任何内容显示(0 of 0)。
这是一个我不管理的票务系统的网页。
- 它可能是什么原因? - 我如何获取文本?

2
使用 element.value。要检查其内部工作原理,您需要启用在元素检查器中查看影子 DOM。 - connexo
谢谢。我将调查一下这个影子 DOM 功能。 - Carlitos_30
2个回答

4

document.getElementById('test').value = 'Hello StackOverflow (on JavaScript)';
<textarea id="test"></textarea>
<textarea>Hello StackOverflow (on HTML)</textarea>

为了从<textbox>元素中获取值,您可以使用几乎相同的JavaScript代码:
 document.getElementById("id").value

 // or in your case

 document.getElementById("arid_WIN_3_536870915").value

非常感谢。我能够使用document.getElementById("id").value捕获文本。 - Carlitos_30

2

如果你想获取textarea当前状态的值,你可以使用JavaScript,像这样:

最初的回答:

 <html>
                  <head>
                    <title>test</title>
                  </head>
                  <body>
                    <textarea onkeyup="getcurrenttext()" id='arid_WIN_3_536870915'>
                    </textarea>
                    <div id='result'></div>
                    <script>
                    function getcurrenttext() 
                    {
                        // Value of textarea at this very moment
                        var textareatext = document.getElementById('arid_WIN_3_536870915').value;
                        // The current text in the textarea should be shown in the console
                        console.log(textareatext)
                        // And also in a div for example purpose
                        document.getElementById('result').innerHTML = textareatext;
                     }
                    </script>
                  </body>
                </html>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接