Using selenium vba I am trying to get the 3rd instance of the classname of searchInput and sendkeys to it. I was able to get it with using xpath,
bot.FindElementByXPath("/html/body/div[9]/div[1]/div/div[1]/input").SendKeys ("test ")
The problem with that is the body div is sometimes 9 and other times 11 and other times 7 and so on.
I have tried:
set parentSearch = bot.findElementByCSS(".searchInput")
parentSearch(3).sendKeys("test")
bot.findElementByCSS(".searchInput")(3).sendkeys("test")
and various others
<div aria-atomic="true" aria-live="polite"></div>
> <div id="cdk-describedby-message-container" style="visibility: hidden;">.</div>
<div ></div>
> <div >...</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 focus-nav-mode="Group" style="background-color: rgb(26, 26, 26);">...</div>
<div 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 > flex
<div > flex
(not in html-the below block)
<div style="color: rgb(255, 255, 255); border-color: rgb(200, 200, 200); background: rgb(26, 26, 26);"> flex
<span title="Search" style="color: rgb(255, 255, 255);"X</span>
<input type="text" aria-label="Search" placeholder="Search" spellcheck="false" 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 Snapshot:
CodePudding user response:
To send a character sequence to the element you can use either of the following Locator Strategies:
Using FindElementByCss:
bot.FindElementsByCss("input.searchInput[aria-label='Search'][placeholder='Search']")([3]).sendkeys("test")
Using FindElementByXPath:
bot.FindElementsByXPath("//input[@class='searchInput' and @aria-label='Search'][@placeholder='Search']")([3]).sendkeys("test")