Short Notes For Interview Perspective:-
1 Check Java installed or not
2 OOPS Concept
3 Data Types
4 Calculate length of String
5 Operators
6 Post Increment
7 Pre Increment
8 While loop
9 For Loop
10 Xpath
11 Relative Xpath
12 Absolute Xpath
13 Syntax for realtive xpath
14 Radio button
15 Check Box
16 Difference between radio button and check box.
17 Dropdown list
18 Handling dropdown list without using "Select" class.
19 Waits
20 Implicit Wait
21 Explicitly Wait
22 WebTable
23 JavaScript
24 Mouse Simulation using action class
25 Drag and Drop (Using Source & Destination)
tive:-
Go to "CMD" & type "java -version" and press Enter
Inheritance
Polymorphism
Abstraction
Encapsulation
1. Primitive - boolean, char, byte, short, int, long, float, double
2. Non Primitive - String, Array
String str = "Hello World";
int len;
len = str.length();
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
int i = 1;
System.out.println(i++); //1
System.out.println(i); //2
int z= 9;
System.out.println(++z); //10
int i=0;
while(i<10)
{
System.out.println("Value of i is " +i);
i++;
}
for (int i=0; i<5; i++)
{
System.out.println("Value of I is : " +i);
}
1. Relative/Partial Xpath
2. Absolute/Complete Xpath
It starts with double forward slash (//)
It starts with single forward slash (/)
1. Using Single attribute: //tagname[@attribute name = 'value1']
2. Using Multiple attribute: //tagname[@attribute1 = 'value1'][@attribute2='value2']
3. Using contains method: //tagname[contains(@attribute,'value1')]
4. Text method: //tagname[text()='text we are searching for']
5. starts-with method: //tagname[starts-with(@attribute-name, '')]
List <WebElement> radios = driver.findElements(By.name(" abc")); // all radio button
System.out.println("Total radio buttons - " + radios.size()); // Total no of radio button
System.out.println(radios.get(0).isDisplayed());
System.out.println(radios.get(0).isEnabled());
System.out.println(radios.get(0).isSelected());
radios.get(1).click();//click the radio button
Same as radio button.
Radio button we can select one but check box we can select multiple.
1. It is also called as list box.
2. Every dropdown will have tagname as "Select"
3. Every element in droplist will have tag "Option"
Steps:
1. Get the xpath of droplist.
2. Send it to the constructor of 'Select' class.
3. Use all the functions using 'Object' of Select class.
Commands:
.getFirstSelectedOption().getText();
.selectByVisibleText(" abc");
.selectByIndex(3);
.selectByValue("4");
.getOptions().size(); //Get all options
.isMultiple(); //tells droplist supports multiple selecting options or not at the same time.
Example:
WebElement month_dropdown = driver.findElement(By.xpath("xpath of drop list"));
Select month = new Select(month_dropdown);
month.selectByIndex(3);
WebElement month_dropdown = driver.findElement(By.xpath("xpath of drop list"));
month_dropdown.sendkeys("April"); // April will be selected from dropdown list.
1. Implicit Wait
2. Explicit Wait
3. Fluent Wait
1. To instruct WebDriver to wait for a specific amount before throwning exception.
Syntax: driver.manage().timeouts().implicitlyWait(30, TimeUnit.Seconds);
1. It is used to halt the execution till the time a particular condition is met or the maximum time has lapsed.
Syntax:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("Xpath Expression")));
Syntax:
1. //table[@class='class name of table']/tbody/tr[row no]/td[column no]
2. driver.findElemnt(By.xpath("//table[@class='dataTable']/tbody/tr[1]/td[1]")).getText(); //Print the data inside
single cell
3. driver.findElemnt(By.xpath("//table[@class='dataTable']/tbody/tr")).size(); // Print total number of rows
4. driver.findElemnt(By.xpath("//table[@class='dataTable']/tbody/tr[1]/td")).size(); //Print total number of column
Syntax:
1. ((JavascriptExecutor)driver).executeScript("document.getElementById('Some Id').value='Selenium'"); //Pass the
value in input box
2. ((JavascriptExecutor)driver).executeScript("document.getElementById('Some Id').click(); // To click
3. ((JavascriptExecutor)driver).executeScript("document.getElementById('Some Id').checked=false"); //To uncheck
the checkbox
1. To do all the mouse simulation we use "Actions" class.
Steps:
1. Find the webElement where we need to do mouse hover
Syntax: WebElement MainMenu=driver.findElement(By.xpath("Xpath Expression"));
2. Mouse simulationn using Action class:
//Create obj of Actions class
Actions act = new Actions(driver);
act.moveToElement(MainMenu).build().perform(); // Used to moving cursor
3. Right click on the page
act.contextClick(MainMenu).build().perform();
Method Names and Usage:
1. moveToElement(WebElement) - Mouse Hover
2. contextClick() - Right click on page
3. contextClick(WebElement) - Right click on WebElement
4. sendKeys(Keys.Tab) - For Keyboard events
5. clickAndHold(WebElement) - click on Element and hold until next operation
6. release() - Release the current control
Sending keyboard "Enter" key
Syntax: act.sendKeys(MainMenu, Keys.Enter).build().perform();
Steps:
1. //Find the elements which needs to be dragged.
WebElement src = driver.findElement(By.xpath("draggable element"));
2. // Find the element which needs to be dropped
WebElement dest = driver.findElement(By.xpath("droppable element"));
3. //Using Actions class
Actions act = new Actions(driver);
act.dragAndDrop(src, dest).build().perform();