简体   繁体   English

如何使用javascript从浏览器获取当前光标样式

[英]how to use javascript get current cursor style from browser

I am using selenium to automation test browser application, I need a javascript api to get the browser current cursor style, not care where it is.我正在使用 selenium 来自动化测试浏览器应用程序,我需要一个 javascript api 来获取浏览器当前的光标样式,而不关心它在哪里。 Is there some API get the information link document.readstate是否有一些API获取信息链接document.readstate

Since it may not have been defined inline, you need the computed style:由于它可能没有被内联定义,因此您需要计算样式:

 document.addEventListener('click', e => { const tgt = e.target; const inline = tgt.style.cursor || "Not defined" const computed = window.getComputedStyle(tgt)["cursor"] console.log("Inline: ",inline,"Computed: ",computed) });
 .help { cursor: help }
 <span style="cursor:pointer">Inline Pointer</span> <hr> <span class="help">CSS help</span>

The following script detect and print out the cursor style browser on any element on your page.以下脚本检测并打印页面上任何元素上的光标样式浏览器。

 document.addEventListener('mouseover',function(e){ var cursor = e.target.style.cursor; console.log(cursor); },false);
 span.crosshair { cursor: crosshair; } span.help { cursor: help; } span.wait { cursor: wait; }
 <p>Mouse over the words to change the cursor.</p> <span style="cursor:auto">auto</span><br> <span style="cursor:crosshair">crosshair</span><br> <span style="cursor:default">default</span><br> <span style="cursor:e-resize">e-resize</span><br> <span style="cursor:grab">grab</span><br> <span style="cursor:help">help</span><br> <span style="cursor:move">move</span><br> <span style="cursor:n-resize">n-resize</span><br> <span style="cursor:ne-resize">ne-resize</span><br> <span style="cursor:nw-resize">nw-resize</span><br> <span style="cursor:pointer">pointer</span><br> <span style="cursor:progress">progress</span><br> <span style="cursor:s-resize">s-resize</span><br> <span style="cursor:se-resize">se-resize</span><br> <span style="cursor:sw-resize">sw-resize</span><br> <span style="cursor:text">text</span><br> <span style="cursor:w-resize">w-resize</span><br> <span style="cursor:wait">wait</span><br> <span style="cursor:not-allowed">not-allowed</span><br> <span style="cursor:no-drop">no-drop</span><br>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM