September 30, 2018

Srikaanth

Cyient Selenium Recently Asked Interview Questions Answers

How to handle Ajax calls?

AJAX allows the Web page to retrieve small amounts of data from the server without reloading the entire page.

To test Ajax application, different wait methods should be applied

ThreadSleep
Implicit Wait
Explicit Wait
WebdriverWait
Fluent Wait

How do you execute your framework from command prompt?

Home-directory > java org,testng.TestNG testng.xml testng2.xml testng2.xml and hit enter

Difference between WebDriver Listener and TestNG listener.

TestNG and Web driver Listener have different interfaces to implement and call them.

WebDriver Event Listener is to listen the events triggered by web driver like beforeClickOn, afterClickOn, beforeFindBy, afterFindBy, etc. and take actions. It is mainly used to write            log file for selenium test execution.

TestNG listener mainly used to generate the report for the test. Also, you can capture screenshot when there is test failure. TestNG events are like onTestFailure, onTestSkipped,                onTestSuccess, etc.
Cyient Selenium Recently Asked Interview Questions Answers
Cyient Selenium Recently Asked Interview Questions Answers

How you will find the row count and column Count in dynamic web table?

     Rows: List<WebElement> rows=htmltable.findElements(By.tagName(“tr”));

     Col:   List<WebElement> columns=rows.get(rnum).findElements(By.tagName(“th”));

WebDriver is interface or class?

WebDriver is interface

Firefox Browser is interface or class?

FirefoxDriver is Class

Syntax to declare chrome browser and Gecko driver and Firefox Browser and IE browser?

Gecko Driver :

System.setProperty(“webdriver.gecko.marionette”, “Path Of Exe”);

WebDriver driver = new FirefoxDriver();

Chrome Driver:

System.setProperty(“webdriver.chrome.driver”,”Path of Exe”);

//create chrome instance

WebDriver driver = new ChromeDriver();

IE Driver :

System.setProperty(“webdriver.ie.driver”,”Path of Exe “);

//create IE instance

WebDriver driver = new InternetExplorerDriver();

Write a Syntax for Drag and Drop?

Actions act = new Actions(driver);

WebElement From = driver.findElement(By.id(“draggable”));

WebElement To = driver.findElement(By.id(“droppable”));

act.dragAndDrop(From, To).build().perform();

Write Syntax for Mouse Hover Element?

Actions act = new Actions(driver);

action.moveToElement(element).build().perform()

Write Syntax for Double Click?

Actions act = new Actions(driver);

action.doubleClick(element).build().perform();

Write Syntax for Right Click?

Actions act = new Actions(driver);

action.contextClick(element).build().perform();

Difference between Apache POI and Jxl jar files?

JExcel Apache POI
It doesn’t support Excel 2007 and Xlsx format. It supports only Excel 2003 and .Xls format It supports both
JXL doesn’t support Conditional formatting It supports
JXL API was last updated in 2009 Apache POI is actively maintained
It doesn’t support rich text formatting Apache POI supports it
It has very less documents and examples as compare to Apache POI It has extensive set of documents and examples

What are all the element locators in Selenium?

Id

Name

CSSSelector

Xpath

Tagname

ClassName

LinkText

Partial LinkText

How to Handle Dropdown Values in selenium. Write a syntax and types to handle the dropdpwn Box?

Using with Select Class

Syntax:

     Select sel = new Select(driver.findElement(By.id(“test”));

     Sel.SelectByVisibleText(“value”);

     Sel.SelectByValue(“2”);

     Sel.SelectByIndex(4);

When will you get element not clickable exception in Selenium?

The reason for the element is not clickable at point(x,y) exception.

      Some of my observation was

It mostly happens in Chrome so if you are mostly working with Firefox or IE then you will not be getting this exception.
Chrome does not calculate the exact location of element
Chrome always click in the middle of Element.
Sometimes you will get this exception due to Sync issue also.

How to solve Not connected Exception – unable to connect to host in selenium webdriver?

Scripts that worked earlier may be till yesterday are NOW not working because of Firefox browser upgraded to new version.

      Most of them have faced the similar problem when the browser has updated to version. This is the first issue user notices when there is an update in the Firefox browser and may not support selenium with the older version of jars.

      If you already have the latest version of selenium, then you have to degrade your browser until there is an update from selenium.

      Problem :

      Webdriver will just initiate the browser, prompting for a search or address and that ends there with an exception:

      org.openqa.selenium.firefox.NotConnectedException:

What is Selenium?

Selenium is a Suite (group) of tools i.e., Selenium IDE, Selenium WebDriver and Selenium Grid to automate web browsers across many platforms.

What is Selenium IDE, WebDriver, and Grid?

Selenium IDE: It is a Firefox plugin which is used to Record and Play the Test Scripts.

Selenium WebDriver: It is a tool which provides an API (that can be understood easily) to automate web browsers with the help of programming languages like Java, Csharp, Python, PHP, Perl, Ruby, and JavaScript.

Selenium Grid: It transparently distributes tests into Remote machines. That is, running multiple tests at the same time against different machines running different browsers and operating systems.

What are the locators available in WebDriver?

Locators: Locators are used to identifying or locate an element (text box, radio buttons, links, check boxes, drop downs, images, text etc. ) in the web page.

Webdriver supports 8 locators i.e., Id, Name, Class Name, Link Text, Partial Link Text, XPath, CSS and Tag Name.

Note: Id is the fastest locator among this 8 locators.

How to launch Firefox, Chrome, IE browser using WebDriver?

The following syntax can be used to launch Browser:

WebDriver driver = new FirefoxDriver();

WebDriver driver = new ChromeDriver();

WebDriver driver = new InternetExplorerDriver();

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();
}
}

Subscribe to get more Posts :