Showing posts with label Selenium Interview Questions. Show all posts
Showing posts with label Selenium Interview Questions. Show all posts

What is the difference between Xpath and DOM (Document Object Model)?


This is the question asked in most of the interviews of Selenium:

DOM: 

The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Objects in the DOM tree may be addressed and manipulated by using methods on the objects.

Ex: var element=document.getElementById("intro");

XPATH: 

XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document.

Ex: //input[@id=”xxx”]

Generate Random Data


In your scripts, you always want to generate random data to automate SignUp forms, below is code to generate random password. If you need script to generate data to complete forms like available here, do write an email to me:

--------------

public static void main(String[] args) {

//can put any array below depending on requirement
String array = "abcde1234567890~!@#$%^&*()_+";

//calculates its length
int i = array.length();

 //password with length 10
for (int j =0; j<=10; j++)

//randomly picking up 10 characters
{
 int k = (int)(Math.random()*i);
char pass = array.charAt(k);
 System.out.print(pass);
 }
 }