excel 如何在Selenium vba中使用类的innerText文本点击元素

uqcuzwp8  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(95)

我愿意获取innerText并点击它。文本为 * 客户服务查询 *。
我试过:

.FindElementsByXPath("//*[text()[contains(.listItem, 'Customer Service Inquiry')]]").Click

这不起作用,因为它给出错误,它不是一个有效的xpath表达式
此外,这工作,但我想点击什么内部文本说。

.FindElementByXPath("//*[@id='listFav_ALLOUTSECURITY0000000000000000008276_APP_P4210_W4210E_PSG0021_20']").click

HTML

<div id="listContentHolder"> == $0 > <div class="carolist" id="listOCL" slot="0" style="height: 57px; top: @px;">.</div> > <div class="carolist" id="listRecipts" slot="1" style="height: 57px; top: 57px;">.</div> <div class="caroList" id="listFav" slot="2" style="height: 153px; top: 114px;"> > <div class="listHeader expanded" id="listFavHeader" oncontextmenu="javascript:CARO.updateDropdownMenuView(this,event);jdebebGUIdoToggleSubMenu(this,'caroTabContextMenu', event, true)
;" toplistitem="false">.</div> <div id="listFavouter" class="listContentOuter" style="height: 128px;"> <div id="listFavInner" class="listContentInner" style="height: 128px; top: Opx;">
<div class="listItem" id="listFav_manageFavs" aria-labelledby="appCaption_fav_manageFavs" role="link" tabindex="0" style="user-select: none; top: Opx;">.</div> > <div class="listItem" id="listFav_ALLOUTSECURITY0000000000000000008582_APP_P4210_W4210E_PSG0099_10" aria-labelledby="appCaption_fav_ALLOUTSECURITY0000000000000000008582_APP_P4210_W 4210E_PSG0099_10" role="link" tabindex="0" style="user-select: none; top: 32px;">.</div> 

<div class="listItem" id="listFav_ALLOUTSECURITY0000000000000000008276_APP_P4210_W4210E_PSG0021_20" aria-labelledby="appCaption_fav_ALLOUTSECURITY0000000000000000008276_APP_P4210_W 4210E_PSG0021_20" role="link" tabindex="0" style="user-select: none; top: 64px;"> <table class="listItem"> 
<tbody>
<tr> > 
<td class="listIcon">.</td>
<td class="listText">Customer Service Inquiry</td> 
</tr> 
</tbody> 
</table> 
</div> 

<div class="listItem" id="listFav_21343ad6_1803cf57c8c__7ffeE1PDJAS3__APP_P41026_W41026E_PSA0001_30" aria-labelledby="appCaption_fav_21343ad6_1803cf57c8c__7ffeE1PDJAS3_APP_P41026_ W41026E_PSA0001_30" role="link" tabindex="0" style="user-select: none; top: 96px;">.</div> </div> <a class="panControl up" necessary="false" style></a>
<a class="panControl down" necessary="false" stylex/a> </div> </div> </div>
owfi6suc

owfi6suc1#

要单击文本为***Customer Service Inquiry***的元素,可以使用以下locator strategies之一:

  • 使用 FindElementByXPathinnerText
.FindElementByXPath("//td[text()='Customer Service Inquiry']").click
  • 使用 FindElementByXPath 沿着 classinnerText
.FindElementByXPath("//td[@class='listText' and text()='Customer Service Inquiry']").click

相关问题