I'm trying to extract the date element of the following page chunk:
<div class="row small edr-process-panel__card-row">
<div class="col-md-6">
<label translate="DETAILS_LAST_SEEN" class="ng-scope">Last Seen</label>
</div>
<!-- ngIf: $ctrl.threat -->
<div class="col-md-6 text-right ng-scope" ng-if="$ctrl.threat" style="">
<label class="ng-binding">28 Nov 06:19:07</label>
</div><!-- end ngIf: $ctrl.threat -->
</div>
<div class="row small edr-process-panel__card-row">
<div class="col-md-7">
<label translate="PREVALENCE" class="ng-scope">Prevalence</label>
</div>
<!-- ngIf: $ctrl.threat -->
<div class="col-md-5 text-right ng-scope" ng-if="$ctrl.threat" style="">
<label class="ng-binding">1</label>
</div><!-- end ngIf: $ctrl.threat -->
</div>
This was working before but not anymore:
lastSeen = driver.FindElement(By.XPath("//label[@translate='DETAILS_LAST_SEEN']/following::label[1]")).Text;
Any idea how I can get the date?
Thanks, John.
我认为您可以使用动态 xpath 的组合
//label[@class='ng-scope' and @translate='DETAILS_LAST_SEEN']//following::label[1]
Try the following:
driver.FindElement(By.XPath("//label[contains(@class, 'ng-binding')]")).Text;
See the following if you need more help with XPaths: Xpath changing after the page gest loaded every time .
Try the following code:
driver.FindElement(By.XPath("//div/label[@class='ng-binding']").Text
Should do the trick.
Seems your xpath
was not correct. Can you try with :
lastSeen = driver.FindElement(By.XPath("//label[@translate='DETAILS_LAST_SEEN']//following::label[1]")).Text;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.