How to select text & How to verify text is bold, italic, underline

5,400 views
Skip to first unread message

Kumar

unread,
Jan 30, 2012, 10:21:27 AM1/30/12
to Selenium Users
Hi there,

I am working on an application named zoomerang.com wherein I get a
popup for survey title.
I am unable to select the text so as to bold it, italic it, and
underline it.
But, I am unable to do it now.

Also, once done, how do I verify the text is bold or italic or
underlined?

Please assist and let me know if you want to know more details.

Thanks in advance,
Alok Kumar

Mike Riley

unread,
Jan 30, 2012, 12:12:38 PM1/30/12
to Selenium Users
Interesting question. I am not sure if that is possible or not, but I
am sure that if it is it would help to know which version of Selenium
you are currently using and which API (Selenium or WebDriver) and in
which language (Java, C#, etc.) you write your code for. The API and
language being used being used being the most important to provide an
answer you will be able to use directly.

Mike

TomL

unread,
Jan 30, 2012, 3:50:06 PM1/30/12
to Selenium Users
It might also depend on how the html is presented. if the bold/
underline/italic is part of the style attribute of the element, you
could use Selenium's get_attribute function:

value = sel.get_attribute("//*[@id='my_element']@style")

and then parse the value depending on what you're looking for
e.g. <id="my_element" style="font-weight:bold;">this whole
paragraph is bold.

Kumar

unread,
Jan 31, 2012, 12:04:07 AM1/31/12
to Selenium Users
Hi Friends,

Thanks for the replies, so far.
I think some are misunderstanding my question.

To be more specific, I am not looking to bold the text using the
selenium commands, but would like to select the text.
Once the text is selected, it will show a button which can be clicked
to bold it. So, basically I would like to select the text and would
like to know how to do that?

Once it is done, I would need to verify whether the text is really
bolded or not. How to do this as well?

I am using Selenium IDE as of now and the application is on DotNet.

Once I am good in this, I would go for Selenium Web Server or RC but
not now.

Thanks,
Alok Kumar.

Mickayla Bachar

unread,
Jul 25, 2016, 3:02:26 AM7/25/16
to Selenium Users
Was there ever a solution to this issue? I am currently trying to do the same thing and cannot figure out how to select the text and see if it is bold. 

David

unread,
Jul 26, 2016, 1:21:42 AM7/26/16
to Selenium Users
Selecting text will require use of javascript - I don't think it's offered natively with Selenium APIs (not even the mouse Actions API), but I could be mistaken. And this javascript route is only available to WebDriver and Selenium RC, no go for Selenium IDE. You can find solutions by searching for terms like "select text javascript" etc. It's not super simple, so there is some block of code to use and some javascript understanding for the user. Here's a sample link: http://stackoverflow.com/questions/985272/selecting-text-in-an-element-akin-to-highlighting-with-your-mouse

As for the bold part, clicking the button to bold it is simple to figure out (assuming the app/site under test is like a rich text editor). Checking whether the text is bold:
  • visually/rendering validation - hard - you'll need image verification tools or a CSS diff/verification tool (similar to image verify but using CSS)
  • code/formatting validation - as TomL mentioned, just fetch the bold formatting from the element. It's either a CSS (inline) style attribute, styled via a class/ID attribute (via CSS), or using the old school <b> (and <i> for italic) HTML tags. For class/ID attribute, you'll only know it's used for bold, etc. if the name implies it, or else you'd have to check the CSS stylesheet file the page uses to format elements. And sometimes a non-standard attribute might be used for such formatting (e.g. not style, not class, not ID but something like <div my-custom-attribute="bold">
Reply all
Reply to author
Forward
0 new messages