Sign up ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

enter image description here

See how the dynamic message displays in the browser. I am adding a name in a text field and clicking save button. After clicking save, a message displays as New Staff added or Staff Name already exists!. I want to get the content of the message. Based on the content I want to proceed with my testcase or end it. How can this be done using selenium?

share|improve this question
This is not a duplicate. The message "New Staff added." is not a JavaScript alert. Its just a HTML container, containing a text. – Niels van Reijmersdal May 16 '14 at 13:23
From attached image, it seems that @Niels is right and message the yellow "alert" is a dynamically created HTML element. You need to find it's id/name/css locator, whichever method to use to find those. – Peter Masiar May 16 '14 at 13:44
I edited the question to call out that this isn't looking for an "alert" but a dynamic element – Kate Paulk May 16 '14 at 14:24
Kate, @Niels, thanks for your persistence. An unfortunate lexical ambiguity, now resolved. – corsiKa May 16 '14 at 17:27
How does the HTML source look? Is the dynamic message hidden/shown by CSS or loaded with JS? – Nicolaj Schweitz Feb 10 at 23:07

3 Answers 3

What you are trying to test feels like pretty basic automated web testing.

  1. Do some action
  2. Wait for new element to appear
  3. Verify content of element

Without the actual HTML its hard for anyone to assist you with identifying the element. Elements are identified in Selenium with different type of selectors.

I think the best advice I can give you is to get better (web testing) knowledge:

  1. Learn HTML and CSS so you understand the structure of the websites/applications, follow the free online course on Codecademy.
  2. Follow Selenium tutorials to understand basic element finding
  3. Read a good Selenium book
share|improve this answer

In chrome, when you manually go through that process, when the message pops up, right click and choose "Inspect Element". This will show you the element in the DOM. Then in your automation code you just create the element and check whether it is displayed.

share|improve this answer

It would be a good idea to use the Firebug plugin in Firefox and load it up beforehand by right clicking on a div close to where this dynamic div gets positioned - then choose "Inspect Element with Firebug" - then perform the action that is supposed to bring up this dynamic div - Firebug will highlight the change in page content for a brief moment that should help you to locate this new div - copy either its id (if set)(highest priority) or classname (if unique)(2nd highest priority) or right click and choose "Copy xpath" (if constant for multiple invocations - could be unlikely)(lowest priority). Then you should be able to apply your requisite condition by extracting .Text from this div.

I recently used this approach to check whether a dynamically generated drop-down list in my application gets displayed above or below its button (so technically a float-up or drop-down list) in a hovering dynamic div.

There is one catch though that you might want to write a wrapper over FindElement() containing a try-catch block so that the webdriver does not break your test in case it cannot find this div. Then you can add the != null condition before extracting the .Text from the div.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.