August 27, 2019

Srikaanth

Genpact Selenium Recently Asked Interview Questions

How to switch from child frame to parent frame?

To switch back from child frame to parent frame use method parentFrame()

Syntax:

driver.switchTo().parentFrame();

Explain how to switch back from a frame?

To switch back from a frame use method defaultContent()

Syntax:

driver.switchTo().defaultContent();
Genpact Selenium Recently Asked Interview Questions Answers
Genpact Selenium Recently Asked Interview Questions Answers

What is the difference between “/” and “//”

Single Slash “/” – Single slash is used to create XPath with absolute path i.e. it locates the element from the root node.

Example:

/html/body/div[2]/div[4]/table/tbody/tr[4]/td/span

Double Slash “//” – Double slash is used to create XPath with relative path i.e.  it locates the element from the current node.

Example:

//input[@name=’email’]

What is the difference between Assert and Verify in Selenium?

There is no difference between Assert and Verify in a positive scenario.

Assert: If the assert condition is true then the program control will execute the next test step but if the condition is false, the execution will stop and further test step will not be executed.

Verify: If the verify condition is true then the program control will execute the next test step but if the condition is false, the execution of the current step will be skipped and further test step will be executed.

What is the super interface of WebDriver?

SearchContext  is the super interface of WebDriver

How to merge all your team members’ code and how you will run?

Git Repository or SVN

How to read and Write the Data from Excel Sheet?

Read Excel Data : FileInputStream.

         Write Excel data : FileOutStream

What is the difference between xpath and css selector?

CSS selectors perform far better than Xpath. Majorly in IE Browser.

Xpath : powerful selection of the DOM
CSS : looks simpler. consistent support across browsers
XPATH: no native support for xpath in IE (WebDriver uses a 3rd party library)
CSS: Tests may need to be updated with UI changes
Xpath engines are different in each browser, hence make them inconsistent
IE does not have a native xpath engine, therefore selenium injects its own xpath engine for compatibility of its API. Hence we lose the advantage of using native browser features that WebDriver inherently promotes.
Xpath tend to become complex and hence make hard to read

Explain Testng.xml structure. ( Suite-> Test> Classes>Class)?

 Example:

<?xml version=”1.0″ encoding=”UTF-8″?>

<suite name=”example suite 1″ verbose=”1″ >

 <test name=”Regression suite 1″ >

   <classes>

     <class name=”com.first.example.demoOne”/>

     <class name=”com.first.example.demoTwo”/>

     <class name=”com.second.example.demoThree”/>

   </classes>

</test>

</suite>

We need to specify the class names along with packages in between the classes’ tags.

What are all the challenges you have faced while doing the Automation.?

Dealing with pop-up windows:
          Selenium can sometimes fail to record common popups in web apps. To handle any kind of alert popup, you can apply a getAlert function. Before actually running the script, you                must import a package that can generate a WebDriver script for handling alerts. The efficient interface brings with it the following commands: void dismiss(), void accept (),              getText(), void sendKeys(String stringToSend). The first two basically click on the “cancel” and “OK” buttons respectively on a popup window.

No event trigger from value changes:
Because Selenium does not initiate events with a change in values, one must do it oneself using fireEvent: selenium.FireEvent(cmbCategory, “onchange”);

      Timeout resulting from synchronization problems:
One should ideally use selenium.IsElementPresent(locator) to verify that the object is in a loop with Thread.Sleep

 Testing Flash apps:
To automate flash apps with Selenium, one can use Flex Monkium. The application source code must be compiled with the swc files generated by Flex Monkium. Then the app and the Selenium IDE are connected, and the tests can be recorded with IDE.

Unexpected error launching Internet Explorer. Browser zoom level should be set to 100% by default for the IE browser to overcome this error.
Protected Mode must be set to the same value error occurs when trying to run Selenium WebDriver on a fresh Windows machine. This issue can be fixed by using capabilities as below when launching IE.

What are Exception and Error? Specify the Difference.?

Exception: Exception occurs in the programmer’s code .which can be handled and resolvable.

Ex: arithmetic exception

DivideByZeroException

NullPointerException

ClassNotFoundException

Error: Errors are not resolvable by the programmer. Error occurs due to lack of system resources.

Ex: Stack overflow

hardware error

JVM error

Why Exception Handling important in Selenium?

To continue the flow of execution.

Most Common Exceptions Which We Notice In Selenium WebDriver?

NoSuchElementException: An element could not be located on the page using the given search parameters.
NoSuchFrameException: A request to switch to a frame could not be satisfied because the frame could not be found.
StaleElementReferenceException: An element command failed because the referenced element is no longer attached to the DOM.
Firefox Not Connected Exception: Firefox browser upgraded to new version.
ElementIsNotSelectable Exception: An attempt was made to select an element that cannot be selected.
unknown command Exception: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource.
ElementNotVisible Exception: An element command could not be completed because the element is not visible on the page.
InvalidElementState Exception: An element command could not be completed because the element is in an invalid state (e.g. attempting to click a disabled element).
UnknownError  Exception: An unknown server-side error occurred while processing the command.
javascript error Exception: An error occurred while executing JavaScript code.
XPathLookupError Exception: An error occurred while searching for an element by XPath.
Timeout Exception: An operation did not complete before its timeout expired.
NoSuchWindow Exception: A request to switch to a different window could not be satisfied because the window could not be found.
InvalidCookieDomain Exception: An illegal attempt was made to set a cookie under a different domain than the current page.
UnableToSetCookie Exception: A request to set a cookie’s value could not be satisfied.
UnexpectedAlertOpen Exception: A modal dialog was open, blocking this operation
NoAlertOpenError Exception: An attempt was made to operate on a modal dialog when one was not open.
ScriptTimeout Exception: A script did not complete before its timeout expired.
InvalidElementCoordinates Exception: The coordinates provided to an interactions operation are invalid.
InvalidSelector Exception: Argument was an invalid selector (e.g. XPath/CSS).

 Explain the difference between Absolute XPath and relative XPath?

Types of X-path

There are two types of XPath:

1) Absolute XPath.

2) Relative XPath.

Absolute XPath:

It is the direct way to find the element.

It will start with the single forward slash(/) –  which means you can select the element from the root node.

Ex : html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[1]/b

Disadvantage:

If there are any changes made in the path of the element then that XPath gets failed.

Relative XPath:

It will starts from the middle of the HTML. It starts with the double forward slash (//).

It which means it can search the element anywhere on the webpage.

Ex :  //*[@class=’featured-box’]//*[text()=’Testing’]

How to Priority your tests in TestNG?
Ex: @Test (priority=1)

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 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.

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.

Subscribe to get more Posts :