Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use chrome dev tools to find elements based on css class or id?

Long time automation developer here (just for context). It's been bugging me for quite a while that the dev tools in chrome used to find elements just don't seem to work as I expect. Hopefully someone can point out what I'm doing wrong.

Looking at , say, sauce labs page: https://saucelabs.com/blog/selenium-tips-finding-elements-by-their-inner-text-using-contains-a-css-pseudo-class

ok now that page has div's and anchors

enter image description here

and indeed I can do find ('a') or find('div')

but why do I have a problem using classes or id's ?

enter image description here

like image 264
Michael Durrant Avatar asked Aug 01 '18 11:08

Michael Durrant


1 Answers

The find() method refers to window.find(), a non-standard API for the browser's built-in Find function. It does not find web elements the same way Selenium or Capybara do, and so it does not parse the input as a selector.

You find elements with selectors in Chrome DevTools using document.querySelector() or document.querySelectorAll(). There are no special methods in Chrome DevTools for this, however it does provide the $() and $$() aliases (respectively) to save you time and keystrokes.

like image 51
BoltClock Avatar answered Nov 15 '22 00:11

BoltClock