1

I am trying to run a test in Selenium IDE, and at the end of the test it looks for the DOM element that is commented out this looks like:

</div><!-- QID: Q1447180888OFH--></body></html>

Obviously the numbers are generated dynamically and I just want to validate that the "QID:" portion is appearing. I am thinking I will have to use the starts-with() command, but not sure if this will work with a commented line of code. Any help with this would be appreciated.

1

Ask your developers to put the comment into div or span with some good name or id, and try to investigate that element (when you can at least locate it - as you have it currently, you cannot even locate that DOM chunk).

If that does not work, you may try to get a span with ink and paper of same color with text QID: Q1447180888OFH, so it will be a real (even invisible) HTML text, which you can get by text attribute of that element with no problems.

And yes, I do try avoid XPATH locators like a pox. :-) Best practices for Selenium suggest to use locators in this order: id > Name > CCS class > XPath. XPATH locators are fragile and slow. Better to spend some time talking to developers.

Adding IDs and names is trivial for developers and huge benefit for QA.

If mission of QA is defined as "Make developers look good", developers want to help QA. Win-win.

1

If the position of the comment is static you can use an Xpath locator. To get the Xpath, inspect the page using Chrome (or Firefox with Firebug), find the element, right-click and select Copy Xpath. Here is an example:

Page for Example: http://www.tutorialspoint.com/html/html_comments.htm

// Comment to Find: <!-- PRINTING STARTS HERE -->
// Use the following value for your *TARGET*
xpath:/html/body/div[3]/div[1]/div/comment()
1

It looks like it could be possible to reach comment element iside oyu body tag with //body::comment(), but unfortunatelly it is not possible in Selenium IDE as it results in error = TypeError: e.scrollIntoView is not a function.

Try to experiment with following knowledge of Xpath contained in this answer, but bear in mind, that Xpath in Selenium IDE could differ.

If you have influence to the development of the product, I recommend that the ID will be inserted into another tag (div/span) which stays hidden.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.