Those elusive Selenium/Python docs!

Just over a month ago, I started transitioning from script development in Selenium/Perl to script development in Selenium/Python. I was flabbergasted by how much time I spent trying to find documentation on the Selenium/Python API! Finally, I located this very valuable wiki page.

My first response was to copy/paste the output of dir(selenium) into a file, and search in the file whenever I needed a particular type of method. Then (following the instructions on the Wiki page), I’d do a print selenium.method.__doc__ to get the full documentation on the method of interest. But that struck me as pretty cumbersome. I longed for a lengthy page full of method name and accompanying documentation, which I could search and read virtually simultaneously.

Then, while I was puzzling over what new assignment I could issue to my beginning Python students next class, it dawned on me. They could produce my longed-for full-length documentation page!

Here’s the teensy program that generates the Selenium-1/Python API:

from selenium import selenium
for call in dir(selenium):
    str = "selenium." + call + ".__doc__"
    print call + ":"
    print eval(str)

And here’s the almost identical program that generates the (unfortunately, also teensy) Selenium-2/Python API:

from selenium import webdriver
for call in dir(webdriver):
    str = "webdriver." + call + ".__doc__"
    print call + ":"
    print eval(str)

I can’t believe how long it took before I finally spent the 5 minutes necessary to develop a tool I really needed. SIGH!

Advertisements

About Mary Ann May-Pumphrey

I'm a software QA automation engineer, focusing primarily on Selenium/Webdriver automation of the front end of web apps. View all posts by Mary Ann May-Pumphrey

2 responses to “Those elusive Selenium/Python docs!

  • ernie (@ernie)

    I struggled with this as well and ended up finding the python documentation generator and online help system (http://docs.python.org/library/pydoc.html)

    The way I do it is “python {path_to_libraries}/pydoc.py -g”

    Launches a little GUI, as well as a local webserver with documentation for all the modules on the system. Easy enough to navigate the GUI (or use the little search dialog provided by the -g flag) to get to the relevant webdriver docs.

  • Jayakumar

    This served my purpose,

    from selenium.webdriver import Firefox
    for each in dir(Firefox):
    if not each.startswith(‘_’):
    print each + ‘:’
    print ‘-‘ * len(each)
    print getattr(Firefox, each).__doc__

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: