I'm working on a VBA Project and my goal is to get the text inside aria-label
. I tried the following VBA code but with no success:
Set hr_ida = driver.FindElementByClass("wtdjmc YMlIz ogfYpf tPgKwe")
MsgBox hr_ida.Attribute("aria-label")
HTML:
<div class="wtdjmc YMlIz ogfYpf tPgKwe" aria-label="Horário de partida: 19:35.">19:35</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>
CodePudding user response:
I think using xpath
is better when there are multiple classes. Try the following
Dim hr_ida As Selenium.WebElement
Set hr_ida = .FindElementByXPath("//div[@class='wtdjmc YMlIz ogfYpf tPgKwe']")
MsgBox hr_ida.Attribute("aria-label")
or using css
like that
Dim hr_ida As Selenium.WebElement
Set hr_ida = .FindElementByCss(".wtdjmc.YMlIz.ogfYpf.tPgKwe")
MsgBox hr_ida.Attribute("aria-label")
CodePudding user response:
Set hr_ida = driver.FindElementByClass("wtdjmc YMlIz ogfYpf tPgKwe")
Compound class names are not permitted and you cannot find the element by using these type of class names. Try below xPaths
Set hr_ida = driver.FindElementByXPath("//div[@class='wtdjmc YMlIz ogfYpf tPgKwe']")
or
Set hr_ida = driver.FindElementByXPath("//div[contains(@aria-label,'Horário de partida:')]")