首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Selenium选择每个复选框并获取其动态下拉列表的标签?

如何使用Selenium选择每个复选框并获取其动态下拉列表的标签?
EN

Stack Overflow用户
提问于 2021-11-23 12:12:19
回答 1查看 28关注 0票数 0

所以我有下面的HTML:

代码语言:javascript
复制
<div data-baseweb="popover" id="bui4" class="fc ap ao gc if ig ih ii ij ik iz g2 j0 j1 io">
   <div class="gc if ig ih ii cj b5">
      <div class="ip iq b6 ag b8">
         <div class="ag b8 hu ae">
            <div class="j5 ag am ai">
               <button data-baseweb="button" class="bm bn ai bo bp bq br bs bt bu bv bw bx by b1 bz c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca ax ay az b0 ig ih if ii cf cg ch ci cj it j6 iv j7">
                  <svg width="16" height="16" viewBox="0 0 24 24" fill="none" color="#000000">
                     <title>Arrow left</title>
                     <path d="M22 13.5H6.3l5.5 7.5H8.3l-6.5-9 6.5-9h3.5l-5.5 7.5H22v3z" fill="currentColor"></path>
                  </svg>
               </button>
               <div class="ax ay az b0">Stores</div>
               <div class="j2 j3"></div>
            </div>
            <div class="ag b8 f3 f5">
               <div data-baseweb="input" class="ar ag cn af ft fu fv fw fx fy fz g0 g1 c1 g2 if ii ig ih ax h6 g3 h7 g5 g6 g7 g8 gc gh g9 j8">
                  <div class="ag ai bo gn c1 g2 ax h6 g3 h7 j9 is cj gc">
                     <svg data-baseweb="icon" title="Search" viewBox="0 0 24 24" class="ja jb jc jd je">
                        <title>Search</title>
                        <path fill-rule="evenodd" clip-rule="evenodd" d="M11 6C8.79086 6 7 7.79086 7 10C7 12.2091 8.79086 14 11 14C13.2091 14 15 12.2091 15 10C15 7.79086 13.2091 6 11 6ZM5 10C5 6.68629 7.68629 4 11 4C14.3137 4 17 6.68629 17 10C17 11.2958 16.5892 12.4957 15.8907 13.4765L19.7071 17.2929C20.0976 17.6834 20.0976 18.3166 19.7071 18.7071C19.3166 19.0976 18.6834 19.0976 18.2929 18.7071L14.4765 14.8907C13.4957 15.5892 12.2958 16 11 16C7.68629 16 5 13.3137 5 10Z"></path>
                     </svg>
                  </div>
                  <div data-baseweb="base-input" class="ag af gb c1 g2 ax h6 g3 h7 cj gc"><input aria-invalid="false" aria-required="false" autocomplete="on" inputmode="text" name="" placeholder="Search" type="text" class="ar it bp br bq bs bt bv bu bw bx af gd ge gf be jf jg gh g9 ax ay g3 g4 cj gi gj" value=""></div>
               </div>
               <div class="ag cu"><button data-baseweb="button" class="bm bn ai bo bp bq br bs bt bu bv bw bx by b1 bz c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca ax ay az b0 cb cc cd ce cf cg ch ci fq ck cl cm jh">Select all</button><button data-baseweb="button" disabled="" class="bm bn ai bo bp bq br bs bt bu bv bw bx by b1 bz c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca ax ay az b0 cb cc cd ce cf cg ch ci jh">Clear</button></div>
            </div>
            <div class="ae j4 hi" style="position: relative;">
               <div style="overflow: visible; height: 0px; width: 0px;">
                  <div aria-label="grid" aria-readonly="true" class="ReactVirtualized__Grid ReactVirtualized__List" role="grid" tabindex="0" style="box-sizing: border-box; direction: ltr; height: 172px; position: relative; width: 375px; will-change: transform; overflow: auto; outline: none;">
                     <div class="ReactVirtualized__Grid__innerScrollContainer" role="rowgroup" style="width: auto; height: 33616px; max-width: 375px; max-height: 33616px; overflow: hidden; position: relative;">
                        <div style="height: 44px; left: 0px; position: absolute; top: 0px; width: 100%;">
                           <label data-baseweb="checkbox" class="bn ag ai c3 jj f3">
                              <span class="jk c1 g2 jl j2 j3 jm jn ar fx fy fz g0 jo jp jq jr js jt ju jv if ig ih ii bx ja jw ah jx jy jz k0 k1 hl k2"></span><input aria-checked="false" type="checkbox" class="im k3 k4 cn be bf fc" value="">
                              <div class="jw is cj ax h6 az h7 af k5 ag am ai k6 k7 k8">
                                 <div>
                                    <div class="ax ay az b0 co cq cn ji">Store 0</div>
                                    <div class="ax ay g3 g4 h8 co cq cn ji">Sample Address</div>
                                 </div>
                              </div>
                           </label>
                        </div>
                        <div style="height: 44px; left: 0px; position: absolute; top: 44px; width: 100%;">
                           <label data-baseweb="checkbox" class="bn ag ai c3 jj f3">
                              <span class="jk c1 g2 jl j2 j3 jm jn ar fx fy fz g0 jo jp jq jr js jt ju jv if ig ih ii bx ja jw ah jx jy jz k0 k1 hl k2"></span><input aria-checked="false" type="checkbox" class="im k3 k4 cn be bf fc" value="">
                              <div class="jw is cj ax h6 az h7 af k5 ag am ai k6 k7 k8">
                                 <div>
                                    <div class="ax ay az b0 co cq cn ji">Store 1</div>
                                    <div class="ax ay g3 g4 h8 co cq cn ji">Sample Address</div>
                                 </div>
                              </div>
                           </label>
                        </div>
                        <div style="height: 44px; left: 0px; position: absolute; top: 88px; width: 100%;">
                           <label data-baseweb="checkbox" class="bn ag ai c3 jj f3">
                              <span class="jk c1 g2 jl j2 j3 jm jn ar fx fy fz g0 jo jp jq jr js jt ju jv if ig ih ii bx ja jw ah jx jy jz k0 k1 hl k2"></span><input aria-checked="false" type="checkbox" class="im k3 k4 cn be bf fc" value="">
                              <div class="jw is cj ax h6 az h7 af k5 ag am ai k6 k7 k8">
                                 <div>
                                    <div class="ax ay az b0 co cq cn ji">Store 2</div>
                                    <div class="ax ay g3 g4 h8 co cq cn ji">Sample Address</div>
                                 </div>
                              </div>
                           </label>
                        </div>
                        <div style="height: 44px; left: 0px; position: absolute; top: 132px; width: 100%;">
                           <label data-baseweb="checkbox" class="bn ag ai c3 jj f3">
                              <span class="jk c1 g2 jl j2 j3 jm jn ar fx fy fz g0 jo jp jq jr js jt ju jv if ig ih ii bx ja jw ah jx jy jz k0 k1 hl k2"></span><input aria-checked="false" type="checkbox" class="im k3 k4 cn be bf fc" value="">
                              <div class="jw is cj ax h6 az h7 af k5 ag am ai k6 k7 k8">
                                 <div>
                                    <div class="ax ay az b0 co cq cn ji">Store 3</div>
                                    <div class="ax ay g3 g4 h8 co cq cn ji">Sample Address</div>
                                 </div>
                              </div>
                           </label>
                        </div>
                        <div style="height: 44px; left: 0px; position: absolute; top: 176px; width: 100%;">
                           <label data-baseweb="checkbox" class="bn ag ai c3 jj f3">
                              <span class="jk c1 g2 jl j2 j3 jm jn ar fx fy fz g0 jo jp jq jr js jt ju jv if ig ih ii bx ja jw ah jx jy jz k0 k1 hl k2"></span><input aria-checked="false" type="checkbox" class="im k3 k4 cn be bf fc" value="">
                              <div class="jw is cj ax h6 az h7 af k5 ag am ai k6 k7 k8">
                                 <div>
                                    <div class="ax ay az b0 co cq cn ji">Store 4</div>
                                    <div class="ax ay g3 g4 h8 co cq cn ji">Sample Address</div>
                                 </div>
                              </div>
                           </label>
                        </div>
                     </div>
                  </div>
               </div>
               <div class="resize-triggers">
                  <div class="expand-trigger">
                     <div style="width: 376px; height: 173px;"></div>
                  </div>
                  <div class="contract-trigger"></div>
               </div>
            </div>
         </div>
         <div class="ic"><button data-baseweb="button" disabled="" class="bm bn ai bo bp bq br bs bt bu bv bw bx by b1 bz c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca ax ay az b0 ig ih if ii cf cg ch ci af">Apply</button></div>
      </div>
   </div>
</div>

这是一个动态的下拉列表,所以如果我向下滚动更多,ReactVirtualized__Grid__innerScrollContainer下的div会显示更多。

这将是我需要的步骤:

1:打开下拉列表,选中第一个复选框,获取门店名称和地址,点击APPLY按钮...

2:打开下拉列表,选择第二个复选框,获取商店名称和地址,单击应用按钮...

3:打开下拉列表,选中第三个复选框,获取店名和地址,点击APPLY按钮...

..。

..。

..。

最后n:打开下拉列表,选择第n个复选框,获取商店名称和地址,单击应用按钮...

但按照步骤操作,必须考虑下拉列表中的动态滚动。

另外,我只想提一下,当点击页面的页面源代码时,我看不到上面的HTML。我只有在打开开发工具时才能看到它。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-23 12:23:33

我使用的一个解决方案是创建一个指向每个结果的路径

代码语言:javascript
复制
//div[@class="ReactVirtualized__Grid__innerScrollContainer"]/div

这将向我展示我可能会有多少结果

然后我将在我的代码中获得它的大小,最后在我得到的大小上创建一个循环,这样它就可以检查每一个当然你可以通过添加你需要的数据来获得你需要的数据

代码语言:javascript
复制
//div[@class="ReactVirtualized__Grid__innerScrollContainer"]/div[i]

我希望它能为你工作!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70080704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档