简体   繁体   English

如何获取CSS网格中的所有元素(包括隐藏元素)

[英]How to get all elements (including hidden elements) in a CSS grid

I want to get all the "Available Items"(check below screenshot) using Javascript at once, but I cannot get all of them at once as I have to use the scroll bar to make the rest of the available service appear in the CSS grid. 我想一次使用Javascript获取所有“可用项”(请查看下面的屏幕截图),但由于无法使用滚动条使其余可用服务出现在CSS网格中,因此无法一次获取所有这些“可用项” 。

<div class="gridWrapper" data-dojo-attach-point="fromGridWrapper">
   <!-- 
      By default, hidden because the same template file is used whether the "from"
      node supports filtering or not - really no reason for 2 files. 
      => The Filtering sub-class will remove the hidden class and attach functionality.
      -->
   <div class="dijit dijitReset dijitInline dijitLeft dijitTextBox filterAvailableItems" id="widget_dijit_form_TextBox_0" role="presentation" widgetid="dijit_form_TextBox_0">
      <div class="dijitReset dijitInputField dijitInputContainer"><input class="dijitReset dijitInputInner" data-dojo-attach-point="textbox,focusNode" autocomplete="off" type="text" tabindex="0" id="dijit_form_TextBox_0" size="20" value=""><span class="dijitPlaceHolder dijitInputField">Filter Available Items</span></div>
   </div>
   <div data-dojo-attach-point="fromNode" id="from_serviceSelect" class="dgrid dgrid-list ui-widget" role="grid" widgetid="from_serviceSelect">
      <div class="dgrid-header dgrid-header-row ui-widget-header">
         <div class="title">Available Items</div>
      </div>
      <div class="dgrid-scroller" style="user-select: none; margin-top: 35px; margin-bottom: 0px;">
         <div class="dgrid-content ui-widget-content">
            <div class="dgrid-preload" style="height: 0px;"></div>
            <div class=" dgrid-row dgrid-row-even ui-state-default dgrid-selected ui-state-active dgrid-focus" id="from_serviceSelect-row-34707" tabindex="0">A Guest is running on Snapshot</div>
            <div class=" dgrid-row dgrid-row-odd ui-state-default" id="from_serviceSelect-row-37729">Active Directory</div>
            <div class=" dgrid-row dgrid-row-even ui-state-default" id="from_serviceSelect-row-31076">Active Directory 2012 - DRA</div>
            <div class=" dgrid-row dgrid-row-odd ui-state-default" id="from_serviceSelect-row-36616">Active Directory Critical</div>
            <div class=" dgrid-row dgrid-row-even ui-state-default" id="from_serviceSelect-row-38883">Active DSOs (Cisco)</div>
            <div class=" dgrid-row dgrid-row-odd ui-state-default" id="from_serviceSelect-row-32796">Active Queue Length </div>
            <div class=" dgrid-row dgrid-row-even ui-state-default" id="from_serviceSelect-row-31583">AD</div>
            <div class=" dgrid-row dgrid-row-odd ui-state-default" id="from_serviceSelect-row-35072">ADTRAN - Device Health</div>
            <div class=" dgrid-row dgrid-row-even ui-state-default" id="from_serviceSelect-row-35420">ADTRAN - Memory</div>
            <div class=" dgrid-row dgrid-row-odd ui-state-default" id="from_serviceSelect-row-37393">Agent Status</div>
            <div class=" dgrid-row dgrid-row-even ui-state-default" id="from_serviceSelect-row-36194">APC PDU</div>
            <div class=" dgrid-row dgrid-row-odd ui-state-default" id="from_serviceSelect-row-31250">APC UPS</div>
            <div class=" dgrid-row dgrid-row-even ui-state-default" id="from_serviceSelect-row-35131">APC UPS - Humidity</div>
            <div class=" dgrid-row dgrid-row-odd ui-state-default" id="from_serviceSelect-row-32621">APC UPS - Temperature</div>
            <div class=" dgrid-row dgrid-row-even ui-state-default" 
        <div class="dgrid-preload" style="height: 7315px;"></div>
     </div>
  </div>
  <div class="dgrid-header dgrid-header-scroll dgrid-scrollbar-width ui-widget-header" style="height: 35px;"></div>
  <div class="dgrid-footer dgrid-footer-hidden"></div>

I was able get all them (including hidden ones) at once several times by change the CSS grid properties, but they were just trial and errors. 通过更改CSS网格属性,我可以一次获得所有这些对象(包括隐藏的对象),但是它们只是试验和错误。 Could anyone please help me? 谁能帮我吗?

例

Although I just see the HTML structure, most probably the widget works in an async way where the divs are only generated for the items / rows that are currently visible. 虽然我只是看到HTML结构,但最有可能的是该小部件以异步方式工作,其中div仅针对当前可见的项目/行生成。

If you really want to simulate user actions or you need to test if the widget works properly then you really need to do that, aka: 如果您真的想模拟用户操作,或者需要测试小部件是否正常工作,那么您真的需要这样做,也就是:

  1. Send Scroll Up / Down events until there is no content change (or if the scrollbar properties change to some values signaling that) 发送向上/向下滚动事件,直到没有内容更改(或如果滚动条属性更改为某些信号来表明这一点)
  2. Collect all Items in-between 收集中间的所有物品
  3. Filter Unqiue ones. 过滤掉不结盟的人。

If this is not a must(you don't do widget validation but E2E testing) then you can dig deep into the internals of the widget and: 如果这不是必须的(您不进行小部件验证,而是进行端到端测试),则可以深入研究小部件的内部结构并:

  1. If the source code is available change it to allow querying all values at once, storing them in hidden divs etc 如果源代码可用,请对其进行更改,以允许一次查询所有值,并将它们存储在隐藏的div等中。
  2. Send an HTTP Request to the server yourself (which would be like the deepest insight) 自己向服务器发送HTTP请求(这可能是最深刻的见解)

I would go with changing the widget - aka implementing a testing / e2e mode for it as well. 我会去改变widget-也为它实现测试/ e2e模式。 That is a must in many modern software projects 在许多现代软件项目中,这是必须的

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

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