August 5, 2019

Srikaanth

Sonata Software Selenium Recently Asked Interview Questions Answers

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 many ways can we load a web page?

We can load a webpage(url) in two ways:

driver.get(“URL”);
driver.navigatr().to(“URL”);
Sonata Software Selenium Recently Asked Interview Questions Answers
Sonata Software Selenium Recently Asked Interview Questions Answers

How can we maximize browser window and delete cookies in Selenium?

To maximize browser window in selenium we use maximize() method.

Syntax:

driver.manage().window().maximize();

To delete cookies we use deleteAllCookies() method.

Syntax:

driver.manage().deleteAllCookies();

 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)

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

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

What are the different Parameters for @Test annotation?

Parameters are keywords that modify the annotation’s function.

Can we run group of test cases using TestNG?

Test cases in group in Selenium using TestNG will be executed with the below options.
If you want to execute the test cases based on one of the group like regression test or smoke test
@Test(groups = {“regressiontest”, “smoketest”})

In what all case we have to go for “JavaScript executor”.

Consider FB main page after you login. When u scrolls down, the updates get loaded. To
handle this activity, there is no selenium command. So you can go for javascript to set
the scroll down value like driver.executeScript(“window.scrollBy(0,200)”, “”);

What are the test types supported by Selenium?

Selenium supports UI and functional testing. As well it can support performance testing
for reasonable load using selenium grid.

What are the different assertions in SIDE?

Assertions are like Assessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this check box is checked”.

Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include “make sure the page title is X” and “verify that this checkbox is checked”.

All Selenium Assertions can be used in 3 modes: “assert”, “verify”, and “waitFor”.

For example, you can “assertText”, “verifyText” and “waitForText”. When an “assert” fails, the test is aborted. When a “verify” fails, the test will continue execution, logging the failure. This allows a single “assert” to ensure that the application is on the correct page, followed by a bunch of “verify” assertions to test form field values, labels, etc.

“waitFor” commands wait for some condition to become true (which can be useful for testing Ajax applications). They will succeed immediately if the condition is already true. However, they will fail and halt the test if the condition does not become true within the current timeout setting (see the setTimeout action below).

How to store a value which is text box using web driver?

driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);

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

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.


Subscribe to get more Posts :