Reputation: 21
I am trying to Automate a custom drop-down field which has DIV, UL and LI. I am unable to use Select class or CSSSelector as this dynamically change.
<div id="boundlist-1092" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default x-border-box x-boundlist-above" tabindex="-1" style="right: auto; left: 495px; top: 245px; height: auto; z-index: 29001; width: 150px;">
<div id="boundlist-1092-listEl" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: auto;">
<ul class="x-list-plain">
<li class="x-boundlist-item" unselectable="on" role="option">Single</li>
<li class="x-boundlist-item" unselectable="on" role="option">Married Filing Jointly</li>
<li class="x-boundlist-item" unselectable="on" role="option">Married Filing Separately</li>
<li class="x-boundlist-item" unselectable="on" role="option">Head of Household</li>
<li class="x-boundlist-item" unselectable="on" role="option">Qualifying Widow(er)</li>
</ul>
</div>
</div>
But, when the element is visible the HTML code looks different
<div id="boundlist-1092" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default x-border-box x-boundlist-above" tabindex="-1" style="right: auto; left: 495px; top: 245px; height: auto; z-index: 29001; width: 150px;">
<div id="boundlist-1092-listEl" class="x-boundlist-list-ct x-unselectable" style="overflow: auto; height: auto;">
<ul class="x-list-plain">
<li class="x-boundlist-item x-boundlist-selected" unselectable="on" role="option">Single</li>
<li class="x-boundlist-item" unselectable="on" role="option">Married Filing Jointly</li>
<li class="x-boundlist-item" unselectable="on" role="option">Married Filing Separately</li>
<li class="x-boundlist-item" unselectable="on" role="option">Head of Household</li>
<li class="x-boundlist-item" unselectable="on" role="option">Qualifying Widow(er)</li>
</ul>
</div>
</div>
It would be of great help if someone could help me with this.
Upvotes: 1
Views: 1088
Reputation: 474001
To locate the dropdown, you can apply a partial match with an XPath expression:
//div[starts-with(@id, "boundlist-")]
Here we are asking to get a div
element with an id
attribute starting with boundlist-
.
To locate dropdown elements inside, I'd use a text match:
//div[starts-with(@id, "boundlist-")]//li[. = "Married Filing Jointly"]
where .
refers to the current element's text.
Upvotes: 1