1

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.

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
bearaman
  • 1,071
  • 6
  • 23
  • 43

4 Answers4

1

I think you can use combination of dynamic xpath

//label[@class='ng-scope' and @translate='DETAILS_LAST_SEEN']//following::label[1]
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
0

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.

John C
  • 3,052
  • 3
  • 34
  • 47
Danny
  • 287
  • 2
  • 15
0

Try the following code:

driver.FindElement(By.XPath("//div/label[@class='ng-binding']").Text 

Should do the trick.

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
  • 1
    This answer was flagged as low-quality because of its **length** and **content**. Consider providing an explanation. – aaron Nov 28 '17 at 17:03
  • Apologies but I edited the web code to show what's really happening. There are multiple elements with the same class so that alone won't work. I need to somehow first locate the element with "DETAILS_LAST_SEEN" and then extract the text from the div element after it. – bearaman Nov 28 '17 at 17:41
  • Gotcha, what's the error that you are getting? It appears to me that the xpath you had before should work. – Mateopotatoe Nov 28 '17 at 17:58
0

Seems your xpath was not correct. Can you try with :

lastSeen = driver.FindElement(By.XPath("//label[@translate='DETAILS_LAST_SEEN']//following::label[1]")).Text;
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • @bearaman Great News !!! Glad to be able to help you out. Please Upvote this/any Answer which was useful to you. – undetected Selenium Nov 29 '17 at 15:23
  • Yes, of course, sorry for the omission. The thing is this was working with a single slash before. The page was then modified and stopped working. I'm going to do some study on xpath to fully understand why it broke and why looking for all descendants did the trick! – bearaman Nov 30 '17 at 09:46
  • @DebanjanB Would be good to include in your answer that the only difference is a typo of `//` as `/` so it's more obvious to readers. – aaron Nov 30 '17 at 10:14
  • @aaron Factually, you can't term it as a **typo** as such. First you need to go through the updated **`XML Path Language (XPath)` Specs** and understand how **`xpath`** works. OP had already mentioned **`The thing is this was working with a single slash before`**. But the **`xpath`** wasn't working now. There are 100 different ways to identify the same `WebElement`. I have chosen the one where OP needs minimal change. Let me know if it makes sense to you. – undetected Selenium Nov 30 '17 at 10:21
  • Yes, that should also go in your answer for completeness :) – aaron Nov 30 '17 at 10:25