find element by id code example

Example 1: javascript get element by id

var element = document.getElementById("YourElementId");

Example 2: getelementbyid

document.getElementById("someid");

Example 3: get element by id in javascript

document.getElementById("YourElementId");

Example 4: find element vs find elements

Differences between findElement and findElementS method?
    --> findElement():
     
      -It does returns SINGLE web element.
      - Return type: WebElement
      - If it cannot find a web element, it throw - NoSuchElementException
          
   
   --> findElements():
      - Returns a List of WebElements
      - Return type: List

Example 5: js getelementbyid

document.getElementById("some_id");

Example 6: javascript get element by id

var myElement=document.getElementById("someElementID");

Tags:

Misc Example