I have a drop down menu which has the text "My Menu". Unfortunately the same drop down is used for another purpose with the text "My Second Menu". I need to click on this "My Menu" drop down and it looks like the following.
<?xml version="1.0" encoding="UTF-8"?>
<div class="c-composedDropdown u-display--flex u-align-items--center u-color--white u-cursor--pointer u-border-radius">
<div class="u-display--flex u-align-items--center">
<span class="flag-icon flag-icon-lg flag-icon-ie composedDropdown__subTitle__icon u-color--white" />
<div>
<div class="u-display--block u-display--flex u-align-items--center">
<span class="u-font-weight--bold u-margin-right--medium">My Menu</span>
<svg xmlns="http://www.w3.org/2000/svg" baseProfile="tiny" width="24" height="24" fill="currentColor" color="#37454D" viewBox="0 0 24 24" class="c-composedDropdown__arrow-icon u-color--blue-lighter">
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M9.5 7l5 5m-5 5l5-5" class="svg-color--primary" />
</svg>
</div>
<p class="c-composedDropdown__subTitle u-display--block">Sample</p>
</div>
</div>
At the moment, I'm using XPath to capture this and it looks like the following.
//*[contains(@class, 'c-composedDropdown') and contains (.,'My Menu')]
The test scenario for this passes fine whenever I run it alone. But when the entire test suite runs, randomly this test fails. That too when running in headless mode. Is there something I can do about the way I pick this element to be clicked? Will that help the test not so flaky? Any suggestions would be much appreciated.