is there a way to find element by id or by classname

4,336 views
Skip to first unread message

Vivian Ho

unread,
May 13, 2014, 2:01:30 AM5/13/14
to nightw...@googlegroups.com
I'm testing a table with cells that have unique id's (dynamically generated).  Some cells are only visible when hovering.  The css or xpath for those cells are not very useful, like: '/li/button'.  But they have an id and a classname that can be easily searched.  Is there a way to do the selenium wd equivalent of getElementByClassName?  Any help is appreciated.

Kerry Doan

unread,
May 14, 2014, 3:23:23 PM5/14/14
to nightw...@googlegroups.com
Per the Nightwatch API pretty much every assertion and command takes a CSS selector as the first argument. If you want to perform a particular Assertion or Command on an element by ID just use the CSS selector for the ID (i.e. "#element-id"), otherwise by class CSS selector (i.e. ".class-name").

So for short example:

browser.url("application url")
  .waitForElementVisible("#element-id", 5000)
  .assert.containsText(".class-name", "Expected Text")
  .end();

Hope that helps.
Message has been deleted

divya gupta

unread,
Sep 17, 2015, 9:19:57 AM9/17/15
to NightwatchJs

No Kerry, this is not working in nightwatch.
Class Css selector not working by (".classname")
Unable to locate element: ".col-md-6 vert-offset-bottom-1" using: css selector
Message has been deleted

Neat Ags

unread,
Sep 23, 2015, 2:10:41 AM9/23/15
to NightwatchJs
Looks like you are providing two css class names ".col-md-6 vert-offset-bottom-1". Try to give one i.e ".col-md-6" or ".vert-offset-bottom-1".
Reply all
Reply to author
Forward
0 new messages