This blog is for Automation Test Engineers

Friday, 16 March 2018

Writing data into excel sheet


FileInputStream fis=new FileInputStream("E:\\data.xlsx");              Workbook wb=WorkbookFactory.create(fis);
Sheet s=wb.getSheet("test");//sheet name
s.createRow(1).createCell(1).setCellValue("Java");
FileOutputStream fos = new  FileOutputStream("E:\\data.xlsx");
 wb.write(fos);
 fos.close();
System.out.println("Success");



                 }


2

How to click on Hyperlink

WebDriver driver= new FirefoxDriver();
driver.get("https://www.google.com"):
driver.findElement(By.linkText("ಕನ್ನಡ")).click();

0

Different types of navigation command


1)driver.navigate().back(): This command takes back the user to previous page of the application.
2)driver.navigate().forward(): This command navigates the user to next page of application
3)driver.navigate().refresh(); This command refreshes the current webpage
4)driver.navigate().to():This command allows the user to launch a new web browser window and navigates to specified URL
Eg:
driver.navigate().to("https://www.google.co.in/");


0

How to enter semicolon

String keys=keys.chord(Keys.SHIFT, Keys.SEMICOLON);

0

How to press Shift+Tab


String keys=keys.chord(Keys.SHIFT, Keys.TAB);

0

How do u read text from hidden element

First we should move cursor over element where element is hidden and we can use getText() method to get the text from hidden element

0

Windows scroll up/down


WebDriver driver= new FirefoxDriver();
driver.get("https://www.flipkart.com/"):
JavascriptExceutor js=new JavascriptExceutor ();
//scroll up
js.executeScript("window.scrollBy(0,450)","");
//scroll down
js.executeScript("window.scrollBy(450,0)","");

0

How to get size of object

WebDriver driver= new FirefoxDriver();
driver.get("https://www.google.com"):
WebElement button=driver.findElement(By.name("btnK"));
System.out.print(button.getSize());


0

How to get tag name

WebDriver driver= new FirefoxDriver();
driver.get("https://www.google.com"):
WebElement button=driver.findElement(By.name("btnK"));
System.out.print(button.getTagName());



0

How to get text of object

WebDriver driver= new FirefoxDriver();
driver.get("https://www.google.com"):
WebElement button=driver.findElement(By.name("btnK"));
System.out.print(button.getText());


0

How to get location of object



WebDriver driver= new FirefoxDriver();
driver.get("https://www.google.com"):
WebElement button=driver.findElement(By.name("btnK"));
System.out.print(button.getLocation());


0

How to get hashcode of object

WebDriver driver= new FirefoxDriver();
driver.get("https://www.google.com"):
WebElement button=driver.findElement(By.name("btnK"));
System.out.print(button.hashcode());


0

How to handle popup in selenium

WebDriver driver =new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.vrlbus.in/vrl2013/register_customer.aspx");
WebElement firstbox=driver.findElement(By.name("FIRSTNAME"));
firstbox.sendKeys("chaitra");
driver.findElement(By.xpath("//input[@type='submit']")).click();
String alertmessage=driver.switchTo().alert().getText();
System.out.print(alertmessage);
0

How to get title of page

System.setProperty("webdriver.ie.driver","E:\\IEDriverServer.exe";
Webdriver driver=new InternetExplorerDriver();
driver.get("https://www.flipkart.com/");
String title=driver.getTitle();
System.out.println(title);


0

How do you open an application in IE broser

System.setProperty("webdriver.ie.driver","E:\\IEDriverServer.exe";
Webdriver driver=new InternetExplorerDriver();
driver.get("https://www.flipkart.com/");

0

How do you open an application in chrome broser

System.setProperty("webdriver.chrome.driver","E:\\chrome.exe");
Webdriver driver=new ChromeDriver();
driver.get("https://www.flipkart.com/");

0

How to handle Autosuggestion in selenium

Webdriver driver =new FirefoxDriver();
driver.get("https://www.google.co.in");
WebElement searchbox=driver.finElement(By.name("q")).senkeys("selenium"));
List<WebElement>autosugg=driver.findElement(By.xpath("//div[contains(text(),'selenium')]
for(int i=1;i<autosugg.size();i++){

System.out.println(autosugg.get(i).getText());
}
0

How to minimize the screen size

Webdriver driver =new FirefoxDriver();
driver.get("https://www.google.co.in");
driver.manage().window().setPosition(new Point(0,-500));
driver.close();


0

How to maximize the screen in selenium

Webdriver driver =new FirefoxDriver();
driver.get("https://www.google.co.in");
driver.manage().window().maximize();
driver.close();

0

Thursday, 15 March 2018

How to clear textbox in selenium

Webdriver driver=new FirefoxDriver();
driver.get("https://www.google.co.in/");
WebElement searchbox=driver.finElement(By.name("q")).senkeys("selenium"));
searchbox.sendkeys(keys.chord(Keys.Control,"a"));
searchbox.sendkeys(keys.BACK_SPACE);
 OR
searchbox.clear();
driver.close();


2