I am creating some test scripts using Selenium WebDriver in C#. The AUT contains a left menu in which the position/ordering of the links depend upon the 'User Preferences' and a lot of factors/configuration from Admin and user side, so XPath is not an option for me.
I used IDE for recording the same and then generating the code, but by default IDE also used XPath, so I added some commands by myself in recorded script and tried to find the element, with the 'Find' button provided in Selenium IDE. After a couple of tries it worked in IDE, i.e. IDE highlighted the element which I want to find, but when I copied the same code in VSTS it is not working.
This is the code generated by IDE, I am not able to get the reason why this is working in IDE and not in VSTS code, I haven't seen any other command to show such a behavior.
driver.FindElement(By.CssSelector("span:contains(Issues Management)")).Click();
This code throws element not found/similar error when executed in WebDriver but works fine in IDE. I have seen a similar post over SQAForums, but that too doesn't explain it's reason well. I am using Firefox as a browser for creating these tests.
HTML of the element is:
<a class="rpLink rpExpandable" title="MyServices" href="#">
<span class="rpOut">
<span class="rpExpandHandle"></span>
<span class="rpText">
Issues Management
<span class="menuItemRole">Container menu item</span>
</span>
</span>
</a>
The complexity is there can be multiple elements with the same text 'Issues Management' on the page, but as far as I know they will be under a different section/class name.