Skip to content

Instantly share code, notes, and snippets.

@santhoshv339
santhoshv339 / ScrollPixelOffset.java
Created January 23, 2017 12:28
Scroll by given pixel Offset
//To scroll down web page by 900 pixels In x(vertical) direction.
//You can y parameter to scroll page In horizontal direction.
JavascriptExecutor javascript = (JavascriptExecutor) driver; javascript.executeScript("window.scrollBy(0,900)", "");
//To scroll up web page by 300 pixels In x(vertical) direction.
javascript.executeScript("window.scrollBy(0,-300)", "");
@santhoshv339
santhoshv339 / OpenLinkNewTab.java
Created January 23, 2017 12:26
Open Link in a new tab
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab);
@santhoshv339
santhoshv339 / MultipleIF
Created January 23, 2017 12:24
MultipleIF
=IF((AND(MOD(E14,2)<>0,MOD(E14,3)<>0)), "Pass", "Fail")
@santhoshv339
santhoshv339 / LastWordExcel
Created January 23, 2017 12:23
Get Last Word(s) After Last/First Instance of a Specified Character
=MID(A1,FIND("=",SUBSTITUTE(A1," ","=",LEN(A1)-LEN(SUBSTITUTE(A1," ",""))))+1,256)
@santhoshv339
santhoshv339 / ScrollEndPage
Created January 23, 2017 12:14
Scroll to end of page
Actions action = new Actions(driver);
action.sendKeys(Keys.PAGE_DOWN);
@santhoshv339
santhoshv339 / ScrollEleView.java
Created January 23, 2017 12:13
Scroll to a particular Element in view
// Create instance of Javascript executor
JavascriptExecutor je = (JavascriptExecutor) driver;
//Identify the WebElement which will appear after scrolling down
WebElement element = driver.findElement(By.xpath(""));
// now execute query which actually will scroll until that element is not appeared on page.
je.executeScript("arguments[0].scrollIntoView(true);",element); //or
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
@santhoshv339
santhoshv339 / FactoryAndDataProvider.java
Created November 21, 2016 13:38
Using Factory and Data provider with Test NG
package com.demo.test;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
public class FactoryAndDataProvider {
private String Source;
private String Desination;
@Factory(dataProvider = "SearchProvider")
@santhoshv339
santhoshv339 / GetHoursBetweenDates.java
Created November 21, 2016 13:36
Get Number of hours between two dates
public class GetHoursBetweenDates {
public static void main(String[] args) {
int timeAMin = toMins("12:15");
int timeBMin = toMins("22:30");
System.out.println(timeBMin);
getJourneyDuration(timeAMin,timeBMin,1,3);
}
public static int toMins(String s) {
@santhoshv339
santhoshv339 / DateDifferenceCheck.java
Created November 21, 2016 13:31
Check number of days difference between two dates
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class DateDifferenceCheck {
public static void main(String[] args) {
SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
String inputString1 = "24 05 2016";
@santhoshv339
santhoshv339 / ActionClassSnippets
Created November 21, 2016 13:30
Some Snippets from Actions Class
public static void goToEndOfPage(WebDriver driver)
{
Actions actions = new Actions(driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
}