Capture Comments Above the <html> Tag


#1

I’m looking to capture a comment that falls above the <html> tag. The comment contains well formatted data that also appears in a table further down, but the table is more difficult to process.

XPath doesn’t work since it starts at the <html> tag and the regex I have also starts at the <html> tag. So the only comments I can capture are after the <html> tag. I have also tried extracting the entire source code but again, I can only extract what comes after the <html> tag.

Does anyone have a work around for this? I appreciate any help.


#2

Extracting text from comments is easy with the sourceExtract command.

From the docs:

The sourceSearch and sourceExtract commands work with the page source, instead of looking at the web page object model (DOM) that all other “classic” Selenium IDE command use. Thus sourceSearch/Extract also “sees” e. g. comments in the page source code and can check/extract Javascript code parts (like the Google Analytics ID) that are invisible to a command like storeText.


#3

Thanks Ulrich. I am using sourceExtract but it seems to only see comments below the <html> tag. So my code looks like this:

sourceExtract | regex=/(<!--[^<]*-->)/@3 | !csvline
csvSave | Comments

That pulls up the third comment after the <html> tag. I need it to pull up the third comment before the <html> tag.