Search code examples
javascriptjquery-selectorswebkit

How do I select the web.whatsapp.com search bar?


I want to programmatically set focus on the web.whatsapp.com search bar:

enter image description here

I inspect this element in Chrome 's source code explorer, and I see this:

enter image description here

I right-click the element, then click "Copy->selector".

It provides: "#side > div.uwk68 > div > div"

So I tried this:

var inputElements = document.getElementsByClassName('#side > div.uwk68 > div > div');

It returns 0 elements.

How could I select this search bar?

Thank you very much!


Solution

  • I think you can use document.querySelector like

    var element = document.querySelector("div._13NKt.copyable-text.selectable-text");
    

    This is listed along with the other things you can use in this reference for the HTML DOM

    https://www.w3schools.com/jsref/dom_obj_document.asp