Search and extract page source code with Selenium IDE command

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.

Both commands can be used in a plain text mode. Then "*" wildcard indicates the changing part.

For experts, the also support standard Regular Expressions (often called regex or regexp).

In sourceExtract, if no match is found, variable is set to "#nomatchfound" - and no error is triggered.

You find full working examples of both commands in the DemoExtract (sourceExtract) and DemoStoreEval (sourceSearch). Both macros get installed with Kantu.

sourceExtract Example

Some text here first. The following examples will operate on it.

  • Coffee $2.95
  • Tea $1.95
  • Milk $2.10

Another test string: width: 11, width: 22, width: 33

Command Target Result (stored in the variable)
sourceSearch $*</li> 3 (= 3 matches found)
sourceSearch regex=[\$\£\€](\d+(?:\.\d{1,2})?) 3 (= 3 matches found, same as before, but now with regular expressions)
sourceSearch Tea $*</li> 1 (= 1 match found)
sourceSearch Beer $*</li> 0 (no match found)
sourceExtract $*</li> $2.95</li> (the coffee, without @ the first match (@1) is assumed)
sourceExtract $*</li>@2 $1.95</li> (the tea)
sourceExtract $*</li>@5 #nomatchfound
sourceExtract regex=[\$\£\€](\d+(?:\.\d{1,2})?)@2 1.95 (the tea)
sourceExtract regex=width: (\d+)@2 width: 22
sourceExtract regex=width: (\d+)@2,1 22 (the 2,1 means the first group of the second match)

Works in

Kantu for Chrome Selenium IDE

Related Demo Macros

ClickandWait is part of almost every demo macro-

The ready-to-import-and-run source code of all demo macros can be found in the Github repository testmacros folder.

See also

clickAndWait, Web Automation Extension User Manual, Selenium IDE commands, Classic Firefox Selenium IDE.

Anything wrong or missing on this page? Suggestions?

...then please contact us.

Kantu Selenium IDE for Chrome and Firefox - Web Test Automation
Subscribe to the a9t9 automation software newsletter . We'll send you updates on new releases that we're working on.