[英]Cannot select a DOM element in Google Chrome Console without inspecting the element first using Chrome Dev Tools
I run into something really strange with Google Chrome Dev Console.我在使用 Google Chrome Dev Console 时遇到了一些非常奇怪的事情。
Firstly I reload my page ( ctrl
+ F5
), then I launch Google Chrome Dev console ( F12
) and try to type in首先我重新加载我的页面(
ctrl
+ F5
),然后我启动 Google Chrome 开发控制台( F12
)并尝试输入
document.getElementById('myElement')
to which Chrome's console responds with: Chrome 控制台的响应是:
null
It's weird because I can actually see my element on the page and after I inspected the element using Chrome Dev Tools (right click on the element and choose Inspect
) and switched back into the Console tab and typed again: document.getElementById('myElement')
I finally got a correct result:这很奇怪,因为我实际上可以在页面上看到我的元素,并且在我使用 Chrome 开发工具检查了元素之后(右键单击元素并选择
Inspect
)并切换回控制台选项卡并再次输入: document.getElementById('myElement')
我终于得到了正确的结果:
<input type="text" id="myElement" class="urEdf2Txt" autocomplete="off" size="10" maxlength="6" value="1.39" />
Note: I always waited until the page is fully loaded and waited until the element is fully visible before trying the procedure described above.注意:在尝试上述过程之前,我总是等到页面完全加载并等到元素完全可见。
this normally happens on iframe
.这通常发生在
iframe
上。 try to see if the target element is in an iframe
in the page.尝试查看目标元素是否在页面中的
iframe
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.