October 1, 2018

Srikaanth

Deloitte 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();
Deloitte Selenium Recently Asked Interview Questions Answers
Deloitte Selenium Recently Asked Interview Questions Answers

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 set System Property in WebDriver?

We can set the system property by using setProperty() method, which is a static method defined in System class for which we need to pass 2 parameters i.e., driver name and path of the executable file of the driver.

For Example Setting system property to launch chrome browser

public class ChromeBrowser {

WebDriver driver;

public static void main(String[] args) {

System.setProperty(“webdriver.chrome.driver”, “E://chromedriver.exe”);

driver = new ChromeDriver();

driver.get(“http://www.google.com”);

}

}

How to find font color of Text element?

By using getCssvalue()

For example:

driver.findElement(By.id(“text”)).getCssValue(“color”);

How to find size of the Image?

By using getSize()

How to find Dynamic Web Elements?

We can Dynamic web elements with the help of XPath or CSS.

For Example:

By using XPath:

driver.findElement(By.xpath(“//div[contains(@id,’yui_’)]”));

By using CSS:

driver.findElement(By.cssSelector(“div[id*=’yui_’)]”));

How to skip a test case in JUnit?

By using @Ignore annotation

@Ignore

@Test

public void testDemo(){

System.out.println(“This is testDemo Method”);

}

@Test

public void testPractice(){

System.out.println(“This is testPractice Method”);

}

Output:

This is testPractice Method

Note: Execution in JUnit is carried out in Alphabetical Order

Which is more preferable xpath or CSS?

CSS Selector

How  to find out all the links in webpage?

List<WebElement> allLinks = driver.findElements(By.tagName(“a”));

How we will configure the Parallel browser testing in testng.xml?

<suite name=”Parallel test suite” parallel=”tests”>

Explain about TestNG – its listeners?

      ITestListener has following methods

OnStart – OnStart method is called when any Test starts.
onTestSuccess– onTestSuccess method is called on the success of any Test.
on test failure– on test failure method is called on the failure of any Test.
onTestSkipped – onTestSkipped method is called on skipped of any Test.
onTestFailedButWithinSuccessPercentage – method is called each time Test fails but is within success percentage.
onFinish – onFinish method is called after all Tests are executed

Write a Syntax to take the screenshot?

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

    //The below method will save the screen shot in d drive with name “screenshot.png” 

    FileUtils.copyFile(scrFile, new File(“D:\\screenshot.png”));

How to find out all the frames in a webpage?

List<WebElement> ele = driver.findElements(By.tagName(“frame”));

     System.out.println(“Number of frames in a page :” + ele.size());

How to handle cookies?

In Selenium Webdriver interact with cookies with below built-in methods

     driver.manage().getCookies();   // Return The List of all Cookies

     driver.manage().getCookieNamed(arg0);  //Return specific cookie according to name

     driver.manage().addCookie(arg0);   //Create and add the cookie

     driver.manage().deleteCookie(arg0);  // Delete specific cookie

     driver.manage().deleteCookieNamed(arg0); // Delete specific cookie according Name

     driver.manage().deleteAllCookies();  // Delete all cookies

What is Selenium Grid?

      Selenium Grid is a tool used together with Selenium RC to run parallel tests across different machines and different browsers all at the same time. Parallel execution means running multiple tests at once.

Features:

Enables simultaneous running of tests in multiple browsers and environments.
Saves time enormously.
Utilizes the hub-and-nodes concept. The hub acts as a central source of Selenium commands to each node connected to it.

Subscribe to get more Posts :