As the title implies I'm currently facing some issues trying to sort this out, the thing is I have an horizontal flex container which shows the Qtrs/Years in order to assign a valid one to a Package Rotation as you'll see on the bottom snippet there are 3 types of "status/classes" that I have to consider, given that certain quarters/years can be set as "Not valid" meaning I shouldn't consider them for the selection itself, leaving me to actually have to first search for the valid quarters (class="quarter valid and class="quarter valid selected, the latter one being the one I currently have selected duh')
Then after actually getting only the valid ones I need to be able to create an XPATH that allows me to travel through those options and be able to select them with an Index or preferably by text (eg: quarterNumber = '3Q' and year = "2021")
Basically the html/dom for that part is this:
<div class="quartersContainer"</div>
<div class="quarter">
<div class="quarterNumber">1Q</div>
<div class="year">2021</div>
<div class="releasedIndicator"></div>
<div class="quarterbar-editing-mode"></div>
</div>
<div class="quarter">
<div class="quarterNumber">2Q</div>
<div class="year">2021</div>
<div class="releasedIndicator"></div>
<div class="quarterbar-editing-mode"></div>
</div>
<div class="quarter valid selected">
<div class="quarterNumber">3Q</div>
<div class="year">2021</div>
<div class="releasedIndicator"></div>
<div class="quarterbar-editing-mode"></div>
</div>
<div class="quarter valid">
<div class="quarterNumber">4Q</div>
<div class="year">2021</div>
<div class="releasedIndicator"></div>
<div class="quarterbar-editing-mode"></div>
</div>
<div class="quarter">
<div class="quarterNumber">1Q</div>
<div class="year">2022</div>
<div class="releasedIndicator"></div>
<div class="quarterbar-editing-mode"></div>
</div>
What I have so far is just this.... (I'm really new to this :( )
//div[contains(@class,'quarter valid') and .//@class='quarterNumber' and .//@class='year']
The whole point of this is to actually generate an XPATH that can be manipulated in a future or through a Behave Feature file for example so testers just have to actually change the text from something like 2Q - 2021 to 3Q - 2023 and it will be able to look for it.
Any advice or guidance would be greatly appreciated :')
Like @DMart is suggesting, do something like this
def build_xpath(year ,quarterNumber):
return "//div[contains(@class,'quarter valid') and .//@class='" + year = "' and .//@class='" + quarterNumber + "']"
And then it's up to you how and with with what values you call build_xpath()