这是Salesforce应用程序。我想从<a>
标签获得以下属性值
HREF
标题
HTML代码
<one-app-nav-bar-item-root one-appnavbar_appnavbar="" data-id="home" data-assistive-id="operationId" aria-hidden="false" draggable="true" class="navItem slds-context-bar__item slds-shrink-none slds-is-active" role="listitem" xpath="1">
<a href="/lightning/page/home" title="Home" tabindex="0" draggable="false" aria-describedby="operationId-14" class="slds-context-bar__label-action dndItem" style="">
<span class="slds-truncate">Home</span>
</a></one-app-nav-bar-item-root>
硒代码(常规脚本语言)
for(int i:(1..size)){
WebElement getHref = driver.findElement(By.xpath("//one-app-nav-bar-item-root[${i}]//a[1]"))
println getHref.getAttribute("href")
println getHref.getAttribute("title")
}
输出
null
null
要提取href
和title
属性的值,必须为visibilityOfElementLocated()
引入WebDriverWait,并且可以使用以下Locator Strategies:
的xpath:
href
:
System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//one-app-nav-bar-item-root/a[//span[text()='Home']]"))).getAttribute("href"));
title
:
System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//one-app-nav-bar-item-root/a[//span[text()='Home']]"))).getAttribute("title"));