Sunday, November 23, 2014

Selenium Interview Questions - Part 2



43. "We have heard about frameworks well it can be broadly classified into these TDD, BDD and ATDD frameworks .What’s the Difference?"

TDD- Test Driven Development, Behaviour Driven Development & Acceptance TestDriven Development

Well, you could see the above Acronyms buzzing over all Automation folks. I was not sure on what it means and How it differs each other. How each methodology will benefit? and where exactly it will help in the Development Life cycle.
Finally, after some analysis I had found out the differences and posting it here. Readers are always welcomed to correct me if I am wrong.
First lets list out what exactly each methodology does means

TDD – Test Driven Development


Its also called test-driven design, is a method of software development in which unit testing is repeatedly done on source code. Write your tests watch it fails and then refactor it. The concept is we write these tests to check if the code we wrote works fine. After each test, refactoring is done and then the same or a similar test is performed again. The process is iterated as many times as necessary until each unit is functionally working as expected. TDD was introduced first by XP. I believe I have explained enough in simple terms.

BDD – Behaviour Driven Development


Behavior-driven development combines the general techniques and principles of TDD with ideas from domain-driven design
DDD-Domain Driven Testing
BDD is similar in many ways to TDD except that the word “test” is replaced with the word “Behaviour”. It’s purpose is to help the the folks devising the system (i.e., the developer) identify appropriate tests to write–that is, tests that reflect the behavior desired by the stakeholders. BDD is usually done in very English-like language helps the Domain experts to understand the implementation rather than exposing the code level tests. Its defined in a GWT format, GIVEN WHEN & THEN.

44. How to change user agent in Firefox by selenium
web driver.
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "some UA string");
Web Driver driver = new FirefoxDriver(profile);
45. What is Selenese?

Selenese is HTML language based command, which is used in Selenium IDE.

54. How to work with radio button in web driver?
We can select the value from the drop down by using 3 methods.
selectByVisibleText - select by the text displayed in drop down
selectByIndex - select by index of option in drop down
selectByValue - select by value of option in drop down
<select id="44"> <option value="1">xyz</option>
<option value="2">abc</option>
<option value="3">pqr</option>
</select>
WebElement e = driver.findElement(By.id("44"));
Select selectElement=new Select(e);
// both of the below statements will select first option in the weblist
selectElement.selectByVisibleText("xyz");

selectElement.selectByValue("1");

55. How to work with dynamic web table?
You can get the total number of <tr> tags within a <td> tag by giving the xpath of the
<td> element by using this function -
List<WebElement> ele = driver.findElements(By.xpath("Xpath of the table"));

Now you can use a for each loop to loop through each of the <tr> tags in the above list
and then read each value by using getText() method.

63. Differences between Selenium web driver,
IDE and RC?
64. How to highlight an object like qtp/uft does
through selenium and java?
public void highlightElement(WebDriver driver, WebElement element) {
for (int i = 0; i < 2; i++)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border: 2px solid yellow;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "");
}}
Call the highlightElement method and pass webdriver and WebElement which you want to highlight as arguments.
65. What are the different assertions in SIDE?
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).
66. How to store a value which is text box using
web driver?
driver.findElement(By.id("your Textbox")).sendKeys("your keyword");
67. 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;};");
68. 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();
69. How to switch between the windows?
private void handlingMultipleWindows(String windowTitle) {
Set<String> windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) { return; } } }
70. 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.
Select a frame by its name or ID. Frames located by matching name attributes are always given precedence over those matched by ID.
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.
71. 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.
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();
}
}
72. 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.
73. 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.
74. How to take the screen shots in seelnium2.0?
// store screenshots
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();

}
}
75. What is the default time for selenium Ide and
webdriver?
Default timeout in selenium ide is 30 seconds.
76. Write down scenarios which we can't automate?
Barcode Reader, Captcha etc.
77. 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.
78. 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.
79. 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();
}
}
80. What is default port no?
4444
81. 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);
82. Does Selenium support https protocols?
Yes
83. 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
84. 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.
85. What is wraps Driver?
For casting selenium instance to selenium2 (webdriver). wraps driver is used.
For more details.
86. 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:
1. @Before public void method() - Will perform the method() before each test. This method
can prepare the test
2. @Test public void method() - Annotation @Test identifies that this method is a test 
method.environment,e.g. read input data, initialize the class)
3. @After public void method() - Test method must start with test@Before - this annotation
is used for executing a method before
87. Difference between assert and verify in selenium
web driver.
  • · When an “assert” fails, the test will be aborted. Assert is best used when the
    check value has to pass for the test to be able to continue to run log in.
  • · Where if a “verify” fails, the test will continue executing and logging the failure.
    Verify is best used to check non critical things. Like the presence of a
    headline element.
88. "I want to find the location of ""b"" in the below
code, how can I find out without using xpath, name,
id, csslocator, index.<div>
<Button>a</button>
<Button>b</button>
<Button>c</button>
</div> driver.findElement(By.xpath("//*[contains(text(),'b')]")).click(); or
 //div/button[contains(text(),'b']
  • ·
89. How to do Applet testing using selenium?
// selenium setup
selenium = new DefaultJavaSelenium("localhost",4444, browserString , url);
selenium.start();
selenium.open(url);

// get the appletfixure to control fest JAppletFixture
AppletFixture dialog = selenium.applet(LIST_APPLET_ID)

// fest similar API for autmation testing
dialog.comboBox("domain").select("Users");
dialog.textBox("username").enterText("alex.ruiz");
dialog.button("ok").click();
90. Name 5 different exceptions you had in
selenium web driver and mention what instance
you got it and how do you resolve it?
  • · WebDriverException
  • · NoAlertPresentException
  • · NoSuchWindowException
  • · NoSuchElementException
  • · TimeoutException
91. How do you manage the code versions in
your project?
  • · Using SVN or other versioning tools
92. Latest version of Firefox and selenium in
market and the version on which you are testing
which you are testing.
  • · FF Latest version till Dec,2013 for windows7,64 bit :26.0.I use FF 25.0.1 (ur ans. may differ)
  • · Selenium web driver latest version till dec,2013- 2.39.0 I use selenium 2.37 see latest at


93. How to know all the methods supported in
web driver
and its syntax.
  • · In Org.openqa.selenium package, web driver interface has all the main methods that can
be used in Selenium Web driver

63. Differences between Selenium web driver,
IDE and RC?
64. How to highlight an object like qtp/uft does
through selenium and java?
public void highlightElement(WebDriver driver, WebElement element) {
for (int i = 0; i < 2; i++)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border: 2px solid yellow;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "");
}}
Call the highlightElement method and pass webdriver and WebElement which you want to highlight as arguments.
65. What are the different assertions in SIDE?
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).
66. How to store a value which is text box using
web driver?
driver.findElement(By.id("your Textbox")).sendKeys("your keyword");
67. 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;};");
68. 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();
69. How to switch between the windows?
private void handlingMultipleWindows(String windowTitle) {
Set<String> windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) { return; } } }
70. 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.
Select a frame by its name or ID. Frames located by matching name attributes are always given precedence over those matched by ID.
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.
71. 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.
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();
}
}
72. 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.
73. 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.
74. How to take the screen shots in seelnium2.0?
// store screenshots
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();

}
}
75. What is the default time for selenium Ide and
webdriver?
Default timeout in selenium ide is 30 seconds.
76. Write down scenarios which we can't automate?
Barcode Reader, Captcha etc.
77. 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.
78. 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.
79. 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();
}
}
80. What is default port no?
4444
81. 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);
82. Does Selenium support https protocols?
Yes
83. 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
84. 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.
85. What is wraps Driver?
For casting selenium instance to selenium2 (webdriver). wraps driver is used.
For more details.
86. 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:
1. @Before public void method() - Will perform the method() before each test. This method
can prepare the test
2. @Test public void method() - Annotation @Test identifies that this method is a test 
method.environment,e.g. read input data, initialize the class)
3. @After public void method() - Test method must start with test@Before - this annotation
is used for executing a method before
87. Difference between assert and verify in selenium
web driver.
  • · When an “assert” fails, the test will be aborted. Assert is best used when the
    check value has to pass for the test to be able to continue to run log in.
  • · Where if a “verify” fails, the test will continue executing and logging the failure.
    Verify is best used to check non critical things. Like the presence of a
    headline element.
88. "I want to find the location of ""b"" in the below
code, how can I find out without using xpath, name,
id, csslocator, index.<div>
<Button>a</button>
<Button>b</button>
<Button>c</button>
</div> driver.findElement(By.xpath("//*[contains(text(),'b')]")).click(); or
 //div/button[contains(text(),'b']
  • ·
89. How to do Applet testing using selenium?
// selenium setup
selenium = new DefaultJavaSelenium("localhost",4444, browserString , url);
selenium.start();
selenium.open(url);

// get the appletfixure to control fest JAppletFixture
AppletFixture dialog = selenium.applet(LIST_APPLET_ID)

// fest similar API for autmation testing
dialog.comboBox("domain").select("Users");
dialog.textBox("username").enterText("alex.ruiz");
dialog.button("ok").click();
90. Name 5 different exceptions you had in
selenium web driver and mention what instance
you got it and how do you resolve it?
  • · WebDriverException
  • · NoAlertPresentException
  • · NoSuchWindowException
  • · NoSuchElementException
  • · TimeoutException
91. How do you manage the code versions in
your project?
  • · Using SVN or other versioning tools
92. Latest version of Firefox and selenium in
market and the version on which you are testing
which you are testing.
  • · FF Latest version till Dec,2013 for windows7,64 bit :26.0.I use FF 25.0.1 (ur ans. may differ)
  • · Selenium web driver latest version till dec,2013- 2.39.0 I use selenium 2.37 see latest at


93. How to know all the methods supported in
web driver
and its syntax.
  • · In Org.openqa.selenium package, web driver interface has all the main methods that can
be used in Selenium Web driver

63. Differences between Selenium web driver,
IDE and RC?
64. How to highlight an object like qtp/uft does
through selenium and java?
public void highlightElement(WebDriver driver, WebElement element) {
for (int i = 0; i < 2; i++)
{
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "color: yellow; border: 2px solid yellow;");
js.executeScript("arguments[0].setAttribute('style', arguments[1]);", element, "");
}}
Call the highlightElement method and pass webdriver and WebElement which you want to highlight as arguments.
65. What are the different assertions in SIDE?
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).
66. How to store a value which is text box using
web driver?
driver.findElement(By.id("your Textbox")).sendKeys("your keyword");
67. 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;};");
68. 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();
69. How to switch between the windows?
private void handlingMultipleWindows(String windowTitle) {
Set<String> windows = driver.getWindowHandles();
for (String window : windows) {
driver.switchTo().window(window);
if (driver.getTitle().contains(windowTitle)) { return; } } }
70. 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.
Select a frame by its name or ID. Frames located by matching name attributes are always given precedence over those matched by ID.
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.
71. 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.
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();
}
}
72. 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.
73. 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.
74. How to take the screen shots in seelnium2.0?
// store screenshots
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();

}
}
75. What is the default time for selenium Ide and
webdriver?
Default timeout in selenium ide is 30 seconds.
76. Write down scenarios which we can't automate?
Barcode Reader, Captcha etc.
78. 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.
79. 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();
}
}
80. What is default port no?
4444
81. 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);
82. Does Selenium support https protocols?
Yes
83. 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
84. 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.
85. What is wraps Driver?
For casting selenium instance to selenium2 (webdriver). wraps driver is used.
For more details.
86. 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:
1. @Before public void method() - Will perform the method() before each test. This method
can prepare the test
2. @Test public void method() - Annotation @Test identifies that this method is a test 
method.environment,e.g. read input data, initialize the class)
3. @After public void method() - Test method must start with test@Before - this annotation
is used for executing a method before
87. Difference between assert and verify in selenium
web driver.
  • · When an “assert” fails, the test will be aborted. Assert is best used when the
    check value has to pass for the test to be able to continue to run log in.
  • · Where if a “verify” fails, the test will continue executing and logging the failure.
    Verify is best used to check non critical things. Like the presence of a
    headline element.
88. "I want to find the location of ""b"" in the below
code, how can I find out without using xpath, name,
id, csslocator, index.<div>
<Button>a</button>
<Button>b</button>
<Button>c</button>
</div> driver.findElement(By.xpath("//*[contains(text(),'b')]")).click(); or
 //div/button[contains(text(),'b']
89. How to do Applet testing using selenium?
// selenium setup
selenium = new DefaultJavaSelenium("localhost",4444, browserString , url);
selenium.start();
selenium.open(url);

// get the appletfixure to control fest JAppletFixture
AppletFixture dialog = selenium.applet(LIST_APPLET_ID)

// fest similar API for autmation testing
dialog.comboBox("domain").select("Users");
dialog.textBox("username").enterText("alex.ruiz");
dialog.button("ok").click();
90. Name 5 different exceptions you had in
selenium web driver and mention what instance
you got it and how do you resolve it?
  • · WebDriverException
  • · NoAlertPresentException
  • · NoSuchWindowException
  • · NoSuchElementException
  • · TimeoutException
91. How do you manage the code versions in
your project?
  • · Using SVN or other versioning tools
92. Latest version of Firefox and selenium in market and the version on which you are testing
which you are testing.
  • · FF Latest version till Dec,2013 for windows7,64 bit :26.0.I use FF 25.0.1 (ur ans. may differ)
  • · Selenium web driver latest version till dec,2013- 2.39.0 I use selenium 2.37 see latest at


93. How to know all the methods supported in
web driver
and its syntax.
  • · In Org.openqa.selenium package, web driver interface has all the main methods that can
be used in Selenium Web driver
95. List the browsers, OS supported by the Selenium
Windows Linux Mac
IE Y NA NA
FF Y Y Y
Safari Y N Y
Opera Y Y Y
Chrome Y Y Y
96. Can you explain Selenium Mobile Automation?
import junit.framework.TestCase;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;

public class OneTest extends TestCase {

public void testGoogle() throws Exception {
WebDriver driver = new AndroidDriver();

// And now use this to visit Google
driver.get("http://www.google.com");

// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));

// Enter something to search for
element.sendKeys("Cheese!");

// Now submit the form. WebDriver will find the form for us from the element
element.submit();

// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
97. 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)
98. What is the difference between single and
double slash
in Xpath?
/
1.It starts selection from the document node
2. It Allows you to create 'absolute' path expressions
3. e.g “/html/body/p” matches all the paragraph elements
//
1. It starts selection matching anywhere in the document
2. It Allows you to create 'relative' path expressions
3. e.g“//p” matches all the paragraph elements
99. 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.
100. 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)", "");