Best approach to find nested elements with WebDriver :When Xpath becomes your best friend

Most of the time, browser automation using WebDriver is all about finding html elements: find a button and click it to perform any action, find an user input text box and set a specific text, find a link and click that links.

But sometimes, even when sounds contradictory, your test is about don’t find an element, for instance that some actions designated to an admin user are not available for a standard user.

There is a significant behavior when you are facing scenarios with nested elements (for instance divs inside divs). It seems like there is a small issue related to nesting. Let me put an example : Given the following HTML output this are the nesting observations:

<div class = "ui-dialog-buttonpane">
    <div class = "ui-dialog-buttonset">
            role = "button"
            class = "ui-button"
            type = "button">
            <span class = "ui-button-text">No</span>
            role = "button"
            class = "ui-button"
            type = "button">
            <span class = "ui-button-text">Yes</span>

If you want to access Yes/No buttons, you first need to find the div identified by the class ui-dialog-buttonpane, then using that IWebElement, you need to find the other div with a class ui-dialog-buttonset. Coding this search, it should be something like :

//Finding modal dialog
var modalDialog = driver.FindElement(By.ClassName("ui-dialog-buttonpane"));

//finding the div that holds the buttons, but finding it within modal dialog
var buttonsDiv = modalDialog.FindElement(By.ClassName("ui-dialog-buttonset"));
//Now you can easily find the buttons within the button
Assert.IsTrue(buttonsDiv.FindElements(By.TagName("button")).count() == 2);

But this way becomes exponentially complex depending with the nesting levels, if you have 5 level nesting, you will need to follow this approach, because the WebDriver won’t find the element from the first level.

XPath becomes your best friend.

Even when there might be some hit to the performance, see Webdriver Xpath Performance, when the XPath expression becomes too long, it helps a lot to find nested elements. Following with our example to find the Yes/No buttons and using Firebug’s FirePah, see First steps with FirePath : What a useful tool , this tool helps me to get the Xpath expression to be used with WebDriver :


And if you are looking for the Xpath expression that returns the two buttons, then just edit the expression to something like this:


Note how the two buttons become  selected.

One more time it’s easy to see how important is to use tools to make things easy 🙂

Posted in Architecture, Browser Automation, FirePath, Selenium WebDriver, Tools | Tagged , , | 4 Comments

Beginning Development on Team Mentor

Code Clueless

Installed Git, cloned the Master source code repository and loaded some XML data with help from Kofi Sarfo.

I’m really liking the rawness of the app. For example, when editing a user, there’s a JSON representation of the user data at the bottom of the screen.

View original post

Posted in Uncategorized | Leave a comment

Creating the Distribution ZIP files for new version of TM

Take the master branch of TM from TeamMentor/Master (thanks Dinis for merging the 3.3 branch into master)

Start TM to have it create the Library_Data directory structure

Remove the following from Library_Data\XmlDatabase\User_Data\TMSecretData.config


Then I created the following \Library_Data\XmlDatabase\User_Data\TMconfig.config

<?xml version=”1.0″?>

And added the libraries to \Library_Data\XmlDatabase\User_Data\TMSecretData.config (x-ed out the sensitive stuff here)


Restarted TM and then reloaded server cache

Then went to each library directory and removed their remotes

Then finally removed the Library configuration from Library_Data\XmlDatabase\User_Data\TMSecretData.config

<Libraries_Git_Repositories />

And started TM

And voila:

Finally I stopped TM. Removed the cache file and zipped up the directory

For OWASP content, I cleared out the TM_Libraries directory

Then added the OWASP repository to \Library_Data\XmlDatabase\User_Data\TMSecretData.config


Started TM

Then stopped TM, removed the OWASP repository from the Library_Data\XmlDatabase\User_Data\TMSecretData.config

And removed the remotes:

Then finally removed the cache and zipped up the directory

Posted in Uncategorized | Leave a comment

Engaging Users with Content

I had a long chat with Dinis yesterday, and it got me charged up about TeamMentor.

I see TM being used to help development teams (the entire team, not just the coders) to build more secure, robust applications. This means the tool has to be genuinely helpful and increase productivity. So things that inhibit productivity, frustrate the user, or overwhelm the user are not helpful and must be eliminated from TM. This concept applies to TM admins as well — make it easy to administer.

Thus, I believe we need to make sure we are constantly considering the user — how would the user do X? Is it obvious? Easy to do? Intuitive? Fast? Spot-on?

Another consideration is making TM more engaging for the user. Granted, it has a fun UI, but that is not sufficiently engaging. You might ask, “What do you mean? It’s a tool. Compilers aren’t engaging. Why should TM be any different?” A fair question. I’d argue that an engaging tool is one that is more likely to be picked up and used. When it comes down to it, in order to TM to be useful, the DevTeam needs to use it all time. That means keeping it open in the IDE or desktop and referencing it all the time. The hard part is getting the user to do that. I’d suggest that making TM more engaging is one way. I don’t have the answers, but I do have some suggestions.

So here are some suggestions for helping to make using TM more engaging for the user.

  1. Allow the user to hit a button that will display a random article, based on current filters or from any of the libraries.
  2. Create a library called Most Popular. It would have one landing page, and it would list in rank order the most popular articles. This should be dynamic, so articles would move up and down the list over time.
  3. Create another library called Must Read or Hot Topics. This would have the 5 or 10 most important articles for a given technology or topic. Perhaps even broken out by basic, intermediate, advanced.
  4. Have another button or library called Today’s Topic. This topic would be displayed by default when a user would login to the site or when the user would click the Today’s Topic button.  This could be set by the admin.
  5. What’s New: show users what the new or updated content. Don’t make them work hard to find it. And with new content showing up daily, folks know that content isn’t getting stale.
  6. Games/Quizzes/Puzzles: Many developers like a good challenge. Perhaps do a 3 or 5 point quiz after certain key topics (things a developer MUST know). The scores could be used by the company to foster healthy competition among the developers. Or have a button that will pop a random chunk of bad code so the user can play “Spot the vulnerability” (maybe something they can copy and paste into their IDE. They would have to fix it.) There is an interesting tool at NIST that has examples of good and bad code: Perhaps some of the most common issues could be used for “Spot the vulnerability” games. If not that, then the SAMATE database had lots of examples of code to include in the detailed write-ups in TeamMentor.


Posted in Content, Future Versions | Tagged | 1 Comment

A path to learn about TeamMentor and receive valuable feedback

This time I would like to share  the way I’m following at TeamMentor to make sure I’m understanding the whole project and provide feedback as well. I’m glad to be part of a very responsive (and smart) team, so I’m always looking for feedback and asking all the questions or observations that to me are not clear.

So the way I always ask my questions is by exposing a use case, a real situation on top of TeamMentor,and by a real situation I mean  a specific case that can be reproducible in any other environment (so it is easy for the other guys to look at it). Then, following Roman’s advice, I always use images,because sometimes is really easy to understand a behavior based on a picture.

I personally  think that asking questions is  a very powerful mechanism to get involved in the product and also be able to provide feedback. So I always ask questions to the other guys and I try to expose my point of view.

For example, my last question about TeamMentor functionality was How TeamMentor search is performed and if we should be removing  trailing characters. Then I attached an image containing both, raw request and raw response and I used some highlighted circles around the white spaces at the end.


As you can see from this picture, we added a white space at the very end of the text under search and there were not results displayed.

Then, the next step is to make this questions and answers available so we can make sure we are creating a strong ecosystem using feedback from the team.

This is the track I’m following now and to be honest I think it has worked fine for me.

Posted in Uncategorized | Tagged , , | 1 Comment

Accessing TeamMentor Debug page for troubleshooting

Even when this is a basic topic, I would like to document where is TeamMentor Debug page (what is the URL) and how it looks like, so we can use it for future references in case you and/or me forget about it.

The first step to be able to access this Debug pages is to make sure you are logged in as Admin. Then depending on your environment, the URL to access that pages should look like this:

After that you should be able to see the Debug page as follow:



There you go! ,now you can enjoy the power of troubleshooting!

Posted in Uncategorized | Tagged , , | 1 Comment

The Importance of Being Earnest (or Why We Need a Honest Real Time Log) in TM

Now that TM has great functionality of site specific TM.config file that is customize-able and overwrites the default config, I naturally started playing with the settings.  The first thing I did was to create the custom file in Library_Data\XmlDatabase\User_Data. I called the file Tmconfig.config and copied one line from the main configuration file –     <SSL_RedirectHttpToHttps>true</SSL_RedirectHttpToHttps>

I changed the true to false as it works well with my testing VM environment. Started TM and tried to access it from outside the box. Well.. nothing happens. Scratching my head for a bit I remembered that TM now has Application Logs. Let me see if there is anything in there… and Hooray! Here is the error I saw in the log 

ERROR: ERROR: There is an error in XML document (1, 6).


ERROR:    ERROR (InnerException): <SSL_RedirectHttpToHttps xmlns=”> was not expected.


ERROR: [handleUserDataConfigActions] failed to load config file from: C:\Dev\eclipseWS\TM\LatestStuff\Dev\Library_Data\XmlDatabase\User_Data\TMConfig.config


Isn’t that amazing? From here I quickly figured out that it requires a whole xml structure to be in place, I changed the xml file to be like:

<?xml version=”1.0″?>







Restarted TM, and there! Everything works as expected.  Without logs, I would be scratching my head for a while longer 🙂

Posted in Uncategorized | Leave a comment