Software Development and QA Tips By QASource Experts

How To Compare Two XML Files in Selenium?

Written by Timothy Joseph | Feb 21, 2022 5:00:00 PM

To compare 2 XML files with selenium, we can use the available utilities. For example, XMLUnit can be used for comparison in Java and XMLDiffPatch with C#.

Below is a sample program to perform XML comparison in C#:

  1. If we are using Visual Studio, we need to download XMLDiffPatch NuGet package.
  2. Then write the below statements in your program to perform the simple comparison.

    XmlDiff xmlcompare = new XmlDiff();
    bool bIdentical = xmldiff.Compare(expectedxml, actualxml);

  3. Here bIdentical will return true if data matches and false if there is any mismatch.
  4. XML files can also be read from a local system using XMLReader.
  5. Similarly, there are other capabilities of this package that can be used to perform XML handling if needed.

Need reliable QA resources to ramp up your existing processes?