Home Ask Login Register

Developers Planet

Your answer is one click away!

Suraj Prasad February 2016

Extract text from Popup using Selenium

enter image description here

Hi All,

I need to find a way how I could get the text from the popup using selenium/core java so that I can compare the text with expected data.

Is there anyway I could extract the text from the popup. Screenshot attached. Thanks in advance.


Marc Sputnik February 2016

If you inspect the element which has the focus. This is possible with all common browsers via development tools or use the SeleniumIDE Plugin for Firefox to get information about that page and build locators. Often framework are used (like bootstrap) to ensure a consistent layout so a CSS-locator might look like:

var popupBody = driver.FindElement(By.CssSelector("div.modal-dialog div.content div.body")

Note that in this case Bootstrap would not the call the class 'popup' but 'modal-dialog'. The locator might furthermore vary depending on the inner structure. As mentioned inspect the element (or share the HTML code so we can suggest concrete locator).

By this you get a normal WebElement ala Selenium where you can get the Text

// use the element
.. popupBody.Text ..

Post Status

Asked in February 2016
Viewed 2,182 times
Voted 5
Answered 1 times


Leave an answer

Quote of the day: live life