Seite 1 von 1

XPath text after element

Verfasst: Montag 30. Januar 2023, 23:29
von Ernie1412
folgendes:

Code: Alles auswählen

<div class="update-info-row">
  <i class="fa fa-calendar">
  </i> 
  <strong>Added:</strong> January 30, 2023
</div>
wie kann ich xpath verwenden damit ich " January 30, 2023" bekomme ?

Code: Alles auswählen

//div[@class='update-info-row']
<-- bekomme ich Added: immer mit

Re: XPath text after element

Verfasst: Dienstag 31. Januar 2023, 06:48
von sparrow
Normalisiert, also weitere Tags im Ziel sind entfernt und der Inhalt des divs wird nach dem schließenden </strong> bis zum Ende des divs gelesen und auch der abschließende Zeilenumbruch entfernt:

Code: Alles auswählen

normalize-space(//div[@class="update-info-row"]/strong/following-sibling::text())

Re: XPath text after element

Verfasst: Dienstag 31. Januar 2023, 10:35
von Ernie1412
da bekomme ich das:
Aufruf mit:

Code: Alles auswählen

Zeit=driver.find_element(By.XPATH,ErstellDatum)
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression normalize-space(//div[@class="update-info-row"]/strong/following-sibling::text()) because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.

Re: XPath text after element

Verfasst: Dienstag 31. Januar 2023, 12:09
von sparrow
Es ist auch kein Node oder Nodeset sondern Text.
Wenn Selenium das nicht kann, solltest du dir das per Stringoperationen aus dem ursprünglichen Ergebnis holen.