September 24, 2018

Srikaanth

Symantec Selenium Recently Asked Interview Questions Answers

How to handle alerts and confirmation boxes.

Confirmation boxes and Alerts are handled in same way in selenium.
var alert = driver.switchTo().alert();
alert.dismiss(); //Click Cancel or Close window operation
alert.accept(); //Click OK
Handle Confirmation boxes via JavaScript,
driver.executeScript(“window.confirm = function(message){return true;};”);

How to mouse hover on an element?

Actions action = new Actions(webdriver);
WebElement we = webdriver.findElement(By.xpath(“html/body/div[13]/ul/li[4]/a”));
action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath(“/expression-here”))).click().build().perform();

How to switch between the windows?

private void handlingMultipleWindows(String windowTitle) {
Set windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) { return; } } }
Symantec Selenium Recently Asked Interview Questions Answers
Symantec Selenium Recently Asked Interview Questions Answers

How to switch between frames?

WebDriver’s driver.switchTo().frame() method takes one of the three possible arguments:

A number.
Select a frame by its (zero-based) index. That is, if a page has three frames, the first frame would be at index “0”, the second at index “1” and the third at index “2”. Once the frame has been selected, all subsequent calls on the WebDriver interface are made to that frame.
A name or ID.
Select a frame by its name or ID. Frames located by matching name attributes are always given precedence over those matched by ID.
A previously found WebElement.
Select a frame using its previously located WebElement. Get the frame by it’s id/name or locate it by driver.findElement() and you’ll be good.

What is actions class in web driver?

Actions class with web Driver help is Sliding element, Resizing an Element, Drag & Drop,
hovering a mouse, especially in a case when dealing with mouse over menus.
Actions class with web Driver help is Sliding element, Resizing an Element, Drag & Drop
Hovering a mouse, especially in a case when dealing with mouse over menus.

Dragging & Dropping an Element:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class testDragandDrop {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/droppable/default.html”);
WebElement draggable = driver.findElement(By.xpath(“//*[@id=’draggable’]”));
WebElement droppable = driver.findElement(By.xpath(“//*[@id=’droppable’]”));
Actions action = new Actions(driver);
action.dragAndDrop(draggable, droppable).perform();
}
}
Sliding an Element:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class testSlider {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/slider/default.html”);
WebElement slider = driver.findElement(By.xpath(“//*[@id=’slider’]/a”));
Actions action = new Actions(driver);
Thread.sleep(3000);
action.dragAndDropBy(slider, 90, 0).perform();
}
}
Re-sizing an Element:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class testResizable {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get(“http://jqueryui.com/resources/demos/resizable/default.html”);
WebElement resize = driver.findElement(By.xpath(“//*[@id=’resizable’]/div[3]”));
Actions action = new Actions(driver);
action.dragAndDropBy(resize, 400, 200).perform();
}
}

Difference between the selenium1.0 and selenium 2.0?

Selenium 1 = Selenium Remote Control.

Selenium 2 = Selenium Web driver, which combines elements of Selenium 1 and Web driver.

Difference between find element () and findelements ()?

findElement() :
Find the first element within the current page using the given “locating mechanism”.
Returns a single WebElement.
findElements() :
Find all elements within the current page using the given “locating mechanism”.
Returns List of Web Elements.

How to take the screen shots in seelnium2.0?

public static void captureScreenShot(String filePath) {
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(filePath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
}

What mobile devices it may Support?

Selenium Web driver supports all the mobile devices operating on Android, IOS operating Systems

Android – for phones and tablets (devices & emulators)
iOS for phones (devices & emulators) and for tablets (devices & emulators)

Write down scenarios which we can’t automate?

Barcode Reader, Captcha etc.

In TestNG I have some test’s Test1-Test2-Test3-Test4-Test5I want to run my execution order is Test5-Test1-Test3-Test2-Test4.How do you set the execution order can you explain for that?

Use priority parameter in @test annotation or TestNG annotations.
public class testngexecution { @Test(priority=2)public void test1(){System.out.print(“Inside Test1”); }@Test(priority=4)public void test2(){System.out.print(“Inside Test2”); }@Test(priority=3)public void test3(){System.out.print(“Inside Test3”); }@Test(priority=5)public void test4(){System.out.print(“Inside Test4”); }@Test(priority=1)public void test5(){System.out.print(“Inside Test5”); }

Differences between jxl and ApachePOI.

jxl does not support XLSX files
jxl exerts less load on memory as compared to ApachePOI
jxl doesn’t support rich text formatting while ApachePOI does.
jxl has not been maintained properly while ApachePOI is more up to date.
Sample code on Apache POI is easily available as compare to jxl.

How to ZIP files in Selenium with an Example?

// Sample Function to make zip of reports
public static void zip(String filepath){
try
{
File inputFolder=new File(‘Mention file path her”);
File outputFolder=new File(“Reports.zip”);
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFolder)));
BufferedInputStream in = null;
byte[] data = new byte[1000];
String files[] = inputFolder.list();
for (int j=0; j<files.length; i++)
{
in = new BufferedInputStream(new FileInputStream
(inputFolder.getPath() + “/” + files[j]), 1000);
out.putNextEntry(new ZipEntry(files[j]));
int totalcount;
while((totalcount= in.read(data,0,1000)) != -1)
{
out.write(data, 0, totalcount);
}
out.closeEntry();
}
out.flush();
out.close();
}
catch(Exception e)
{
e.printStackTrace();
return “Fail – ” + e.getMessage();
}
}

What is default port no?

4444

If Default port no is busy how to change port no?

We can use any port number which is valid.. First create an object to remote control configuration.
Use ‘setPort’ method and provide valid port number(4545,5555,5655, etc).. There after attach this
remote control configuration object to selenium server..i.e
RemoteControlConfiguration r= new RemoteControlConfiguration();
r.setPort(4567);
SeleniumServer s= new SeleniumServer(r);

Does Selenium support https protocols?

Yes

Majorly asked test scenario with framework in Interviews?

Majorly asked are:

Login for Gmail scenario
Goggle search and finding no of results
Downloading a file and save it
Checking mails and deleting them
Do shopping in flipkart.com

Selenium support mobile applications?

No, it is browser automation tool, it only automates Websites opening in mobile browser, and mobile APPs can’t be automated.

What is wraps Driver?

For casting selenium instance to selenium2 (webdriver). wraps driver is used.

Can you explain Junit Annotation? If there are 1000 test cases. 500 test cases are executed. How will you execute the rest of the test cases by using annotation?

The annotations generated with JUnit 4 tests in Selenium are:

@Before public void method() – Will perform the method() before each test. This method can prepare the test
@Test public void method() – Annotation @Test identifies that this method is a test method.environment,e.g. read input data, initialize the class)
@After public void method() – Test method must start with test@Before – this annotation is used for executing a method before.


Subscribe to get more Posts :