DOM Monster and Selenium

Santi tweeted a link to DOM Monster which I think I had seen before but for some reason decided to spend the hour to cobble up a Se script that will fetch the information it provides on a page.

I’m not sure I’d actually use this since most of the information it provides is likely a result of importing 3rd party JS libs into your code, but off the top of my head you could…

  • Run it against each page in the Page Object __init__
  • Fail scripts if there are any warnings
  • Filter known messages you don’t care about
  • Compare against known amounts of messages and alert a human if it has changed


import CustomTestCase
from nose.plugins.attrib import attr
from nose.plugins.skip import SkipTest
class MonsterExample(CustomTestCase.CustomTestCase):
    def whos_da_monster(self):
        Clever function for getting DOM Monster ( information from a page.
        # navigate to the page you want. this example uses page objects so just
        # ignore the 'how' we get the page
        p = self.login_as_reviewer()
        dashboard = p.goto_random_draft_project()
        except Exception as e:
            if str(e).find("Timed out after") != -1:
            warns = []
            for warn in range(0, int("//div[text()='warn']"))):
                warns.append("xpath=(//div[text()='warn'][1]/..)[%s]" % str(warn + 1)).split("\n")[1].strip())
            tips = []
            for tip in range(0, int("//div[text()='tip']"))):
                tips.append("xpath=(//div[text()='tip'][1]/..)[%s]" % str(tip + 1)).split("\n")[1].strip())
        # do stuff with the warnings
        self.assertEqual([], warns)

Post a Comment

Your email is never published nor shared. Required fields are marked *