Laurenz Z
Laurenz Z

Reputation: 101

XPath, nested conditions

I have the following HTML code, and I need to have an XPath expression, which finds the table element.

<div>
   <div>Dezember</div>
   <div>
       <div class="dash-table-container">more divs</div>
   </div>
</div>

My current Xpath expression:

//div[./div[1]/text() = "Dezember"]/preceding::div[./div[2][@class=dash-table-container]

I don't know how to check if the dash table container is the last one loaded, since I have many of them. So I need the check if it's under the div with "Dezember" as a text because the div's before with the other months are being loaded faster. I want the XPATH to select the "dash table container" div. Thanks in advance

Upvotes: 0

Views: 332

Answers (2)

zx485
zx485

Reputation: 29022

To select the div with the text content of "more divs", you can use

//div/div[@class="dash-table-container" and ../preceding-sibling::div[1]="Dezember"]

and to select its parent div element, use

//div[div/@class="dash-table-container"][preceding-sibling::div[1]="Dezember"]/..

Upvotes: 1

Laurenz Z
Laurenz Z

Reputation: 101

I figured it out.

//div[preceding-sibling::div="Dezember"]/div[@class="dash-table-container"]

worked perfectly for me.

Upvotes: 0

Related Questions