如何在 Selenium vba 中使用 class 的 innerText 文本单击元素
How to click on the element using the innerText text of a class in Selenium vba
我愿意获取innerText并点击它。正文为客服咨询.
我试过:
.FindElementsByXPath("//*[text()[contains(.listItem, 'Customer Service Inquiry')]]").Click
这不起作用,因为它会给出错误,表明它不是有效的 xpath 表达式
此外,这可行,但我想点击内部文字所说的内容。
.FindElementByXPath("//*[@id='listFav_ALLOUTSECURITY0000000000000000008276_APP_P4210_W4210E_PSG0021_20']").click
html
<div id="listContentHolder"> == [=14=] > <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>
要单击文本为客户服务查询的元素,您可以使用以下任一方法:
使用 FindElementByXPath 并且仅 innerText:
.FindElementByXPath("//td[text()='Customer Service Inquiry']").click
使用 FindElementByXPath 以及 class 和 innerText:
.FindElementByXPath("//td[@class='listText' and text()='Customer Service Inquiry']").click
我愿意获取innerText并点击它。正文为客服咨询.
我试过:
.FindElementsByXPath("//*[text()[contains(.listItem, 'Customer Service Inquiry')]]").Click
这不起作用,因为它会给出错误,表明它不是有效的 xpath 表达式
此外,这可行,但我想点击内部文字所说的内容。
.FindElementByXPath("//*[@id='listFav_ALLOUTSECURITY0000000000000000008276_APP_P4210_W4210E_PSG0021_20']").click
html
<div id="listContentHolder"> == [=14=] > <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>
要单击文本为客户服务查询的元素,您可以使用以下任一方法
使用 FindElementByXPath 并且仅 innerText:
.FindElementByXPath("//td[text()='Customer Service Inquiry']").click
使用 FindElementByXPath 以及 class 和 innerText:
.FindElementByXPath("//td[@class='listText' and text()='Customer Service Inquiry']").click