使用 selenium v??ba 我試圖獲取 searchInput 的類名的第三個實體并將其發送給它。我能夠使用 xpath 獲得它,
bot.FindElementByXPath("/html/body/div[9]/div[1]/div/div[1]/input").SendKeys ("test ")
問題是 body div 有時是 9,有時是 11,有時是 7,依此類推。
我努力了:
set parentSearch = bot.findElementByCSS(".searchInput")
parentSearch(3).sendKeys("test")
bot.findElementByCSS(".searchInput")(3).sendkeys("test")
和其他各種
<div class="cdk-live-announcer-element cdk-visually-hidden" aria-atomic="true" aria-live="polite"></div>
> <div id="cdk-describedby-message-container" class="cdk-visually-hidden" style="visibility: hidden;">.</div>
<div class="cdk-overlay-container"></div>
> <div class="tutorial-popup-container">...</div>
<div id="svgProviderContainer" style="display: none;"></div>
<div style="left: -1000px; overflow: scroll; position: absolute; top: -1000px; border: none; box-sizing: content-box; height: 200px; margin: Opx; padding: Opx; width:
200px;">...</div>
><div class="slicer-dropdown-popup visual" focus-nav-mode="Group" style="background-color: rgb(26, 26, 26);">...</div>
<div class="slicer-dropdown-popup visual" focus-nav-mode="Group" style="background-color: rgb(26, 26, 26); width: 101.625px; transform: scale(0.572222); left: 378.722
px; top: 120.944px; transform-origin: left top; display: none;"> == $0
<div class="slicer-dropdown-content"> flex
<div class="slicerContainer isMultiSelectEnabled"> flex
(not in html-the below block)
<div class="searchHeader show" style="color: rgb(255, 255, 255); border-color: rgb(200, 200, 200); background: rgb(26, 26, 26);"> flex
<span class="powervisuals-glyph search icon searchIcon" title="Search" style="color: rgb(255, 255, 255);"X</span>
<input type="text" aria-label="Search" placeholder="Search" spellcheck="false" class="search Input" drag-resize-disabled="true" style="background: rgb(26, 26,
26); color: rgb(255, 255, 255); font-size: 10.6667px; font-family: Tahoma;" pbi-focus-tracker-idx="9">
</div>
HTML 快照:

uj5u.com熱心網友回復:
要將字符序列發送到元素,您可以使用以下任一定位器策略:
使用FindElementByCss:
bot.FindElementsByCss("input.searchInput[aria-label='Search'][placeholder='Search']")([3]).sendkeys("test")使用FindElementByXPath:
bot.FindElementsByXPath("//input[@class='searchInput' and @aria-label='Search'][@placeholder='Search']")([3]).sendkeys("test")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/390972.html
上一篇:使用表之間查找的陣列的總和
下一篇:如何使用索引并匹配兩列?
