How to find out DOM and CSS address to an element for Selenium?

Tags: css,dom,selenium

Problem :

I have a following element (Login box):

<input type="text" style="font-family: Verdana; font-size: 11px; width: 180px;" id="ctl00_Content_ctl00_Login2_UserName" maxlength="50" name="ctl00$Content$ctl00$Login2$UserName">

Because I have a Firebug, if I right click on on the element it gives me XPath address (//*[@id="ctl00_Content_ctl00_Login2_UserName"]).

As per Selenium website, I am suppose to be able to click on the element also by DOM and by CSS. How do I do it? Is there an easy tool (browser add-on) available for this purpose? I just don't want to be limited by id and xpath alone.

Solution :

CSS locator would be


DOM Locator would be


    CSS Howto..

    How do I make an expanding textbox?

    how to set the background color of the whole page in css

    How to upgrade web project with latest fancy Bootstrap & SASS

    How to distribute p:menuitems in p:menubar accordingly?

    How to create a fixed div inside an another div?

    How to get a small div bar to slide down a menu on mouseover

    how to use bootstrap's modal dialog only, instead of the whole bootstrap.css to aviod conflicting with my own css

    CSS: How to fill a dynamic container that contains fixed sized elements?

    CSS box-shadow shows weird white region?

    How to change CSS style of nested list items?

    How do I center a button in an angular-ui-grid cell?

    How to select part of a custom element with CSS?

    How to fix IE support for line break using CSS pseudo-element?

    How do I give a WordPress Custom Menu item an id or class for CSS targeting?

    How to create a list with 'pinned' items

    How to truly align center of two elemnts with css?

    how to get this modal window to work correctly?

    How to create a
      with a triangle for the :active row?

    How to make Bootstrap container auto for height?

    How to make div elements inside a div background image responsive using css

    How do I add hover cursor and still get move cursor on JQuery Table Sortable?

    How to overlap divs in html

    How do I remove a hover effect if the Element has focus?

    How do I make
  • with block elements sit beside each other?
  • How to add text using css in textarea? [closed]

    how to center text html css

    Basic concept for how javascript replaces an html input with something interactive?

    HTML, CSS: how can I merge these divs in order to use float:left property on their children?

    Trying to highlight table row using JQuery but not working, can anyone tell me why and how to fix it?

    How to select the first occurrence of an HTML element in CSS that does not have a specific class?