Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99418

How to find element using xpath when dom changes with window size

$
0
0

The DOM my test application changes depending upon the window size. So I am trying to write an XPATH which will cater for both of these scenarios.

Scenario 1: When the window is maximum size below is the dom:

<tbody>
<tr><td class="sv-table-col-xs"><img src="image.gif">
</td>
<td>03/Mar/2020</td>
<td><span class="sv-label sv-label-primary">You</span>
</td><td>0% of 1</td>
<td><a href="../run/SIW_TCC.start_url?B30558D84DB411EAMPZFJ0LZCJDZzBZnQ_">Complete academic review</a></td>
</tr>
</tbody>

I am using xpath:

//tr[td[contains(text(), '03/Mar/2020')]]//a[text()='Complete academic review']

This works fine and finds the element.

Scenario 2: Below is the DOM when window is shrinked

<tbody>
<tr><td class="sv-table-col-xs">
<b class="tablesaw-cell-label">Status</b>
<span class="tablesaw-cell-content"><img src="../images/emailunr.jpg" style="border:0px" alt="..\images\icons\exploding_email1.gif.gif"></span>
</td>
<td><b class="tablesaw-cell-label">Due Date</b>
<span class="tablesaw-cell-content">03/Mar/2020</span>
</td>
<td><b class="tablesaw-cell-label">Primary Reviewer</b>
<span class="tablesaw-cell-content"><span class="sv-label sv-label-primary">You</span></span>
</td>
<td class="tablesaw-cell-hidden"><b class="tablesaw-cell-label">Other Reviewers</b>
<span class="tablesaw-cell-content">0% of 1</span>
</td>
<td class="tablesaw-cell-hidden"><b class="tablesaw-cell-label">Action</b><span class="tablesaw-cell-content">
<a href="6WSa-XlcD796Q">Complete academic review</a>
</span></td></tr>
</tbody>

For this the xpath changes to:

//tr/td[5]/span/a

to get to both elements I have tried to use:

//tr/td[5]/span/a | //tr[td[contains(text(), '03/Mar/2020')]]//a[text()='Complete academic review']

this xpath works but I on shrinked window I am not validating the element with text contains ''03/Mar/2020'& 'Complete academic review'. Not sure if there is a way to validate the texts in both scenarios before selecting the element.


Viewing all articles
Browse latest Browse all 99418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>