Wednesday, August 13, 2014

Some interview questions on webdriver.

1.   which framework you have used in ur project?
2.    what is hybrid framework?
3.    what is xpath
4.    what is // and / in xpath
5.    which selenium version ur working
6.    How do find the xpath?
8.    Explain about selenium architecture
9.    What is Selenium IDE
10.    What is Selenium Webdriver
11.    Have you used TestNG
12.    What is annotations
13.    how do you read data from excel
14.    How do you handle popups
15.    What is the use of Xpath
16.    Different types of locators
17.    Selenium Framework that you are using in your current project?
18.    How do you identify the Xpath of element on your browser?
19.    Selenium function used for retrieving the attribute or value?
20.    How do you differentiate check box if more than one check box is existed in your application?
21.    Difference between Assert and Verify?
22.    What is the alternate way to click on login button?
23.    How do you verify if the checkbox/radio is checked or not
24.    How to get the href of a link / get the source of image
25.    Count the number of links in a page
26.    How to check all checkboxes in a page
27.    How do you handle browser popup?
28.    How do you handle elements present inside frame?
29.    How do you handle Javascript alert/confirmation popup?
30.    How do you launch IE/chrome browser?
31.    How to perform right click using WebDriver?
32.    How do perform drag and drop using WebDriver?
33.    How to send ENTER/TAB keys in WebDriver?
34.    Example for method overload in WebDriver
35.    How do you upload a file?
36.    How do you click on a menu item in a drop down menu?
37.    How do you work with page onload authentication popup / windows based popup?
38.    How do you simulate browser back and forward?
39.    How do you get the current page URL?
40.    What is an xpath?
41.    What is the difference between ‘/’ and ‘//’
42.    What is the difference between findElement and findElements?
43.    How do you achieve synchronization in WebDriver?
44.    Explain implicit and explicit wait
45.    Write the code for Reading and Writing to Excel through Selenium
46.    How do get typed text from a textbox?
47.    What are the different exceptions you get when working with WebDriver?
48.    What are the languages supported by WebDriver?
49.    What are the limitations of Selenium IDE?
50.    What are the browsers supported by Selenium IDE?
51.    How do you clear the contents of a textbox in selenium
52.    What is a Framework?
53.    Different components of your framework?
54.    Can you explain the Framework flow with a diagram?
55.    How do you accommodate project specific methods in your framework?
56.    How is the failure handled in your framework?
57.    What kind of reports are generated by your framework?
58.    What are the prerequisites to run selenium webdriver?
59.    What are the advantages of selenium webdriver?
60.    What is webdriver backed selenium?
61.    How to invoke an application in webdriver?
62.    What is Selenium Grid?
63.    How to get the number of frames on a page?
64.    How to verify that an element is not present on a page?
65.    How do you simulate scroll down action?
66.    What is Robot class?
67.    How do you verify that the given list of numbers on a web page is sorted in ascending order?
68.    How to verify the presence of the success message on a page?
69.    Which  is the package which is to be imported while working with webdriver?
70.    How to check if an element is visible on the web page?
71.    How to check if a button is enabled on the page?
72.     How to check if a text is highlighted on the page?
73.     What is the selenium's recording language?
74.    How do you handle Ajax controls using selenium?
75.    How to check the checkbox or radio button is selected?
76.    How to get the title of the page?
77.    How do u get the width of the textbox?
78.    How do u get the attribute value of the web element?
79.    How to check whether a text is underlined or not?
80.    How to change the URL on a webpage using selenium web driver?
81.    How to verify the presence of tooltips for a link?
82.    How to hover the mouse on an element?
83.    What is the use of getOptions() method?
84.    What is the use of deSelectAll() method?
85.    Is WebElement an interface or a class?
86.    FirefoxDriver is class or an interface and from where is it inherited?
87.    Which is the super interface of webdriver?
88.    What is the difference b/w close() and quit()?
89.    What is the difference b/w getWindowHandles() and getWindowHandle() ?
90.    What is the use of contextClick() ;
92.    How to perform double click using webdriver?
93.    What is the use of AutoIt?
94.    How to type text in a new line inside a text area?
95.    How to switch back from a frame?
96.    What is the use of getPageSource()?
97.    Can you handle flash using web driver?
98.    How do you send ENTER/TAB keys in webdriver?
100.    What is the benefit of using TestNG?
what are all the challenges You have faced while automating multiple browser?
how to count the no of column/Row in web table? ant print all the values
how to read and write the data from Xl/Note pad
how you handle if Element present in inside the iframe


Now with answers:

1. Which framework you have used in ur project?

Ans: I have used Selenium Hybrid framework

2. What is hybrid framework?

Hybrid framework is combination of Data Driven, Method Driven, Keyword Driven, Module Driven framework In our project Your_Project_Name (ex- CustomerCentre) ,
we are using Hybrid Framework(why framework required)
Basically this involves 3 stages-

1) Designing the framework,
2) Implementing the framework,
3) Execution of the framework.
1) Designing the framework-

a) while designing the fw in anyone of the local drive create a folder by name HybridFramework. Launch the eclipse, set the workspace to HybridFramework.
b) in eclipse create a java project by name CustomerCentre.
c) in eclipse under CustomerCentre proj create a folder Jars & to that Jars folder include all
the jar files related to the project such WebDriver jar, poi jar etc.
d) in eclipse under CustomerCentre proj create another folder by name Drivers to this folder copy all the executable files or driver such as Chrome Driver,
IE driver and so on.

When designing the framework there are methods which can be used in more than one project such methods we call it as Generic method. And there are methods
which are related to only one single project those methods are called as project specific method.

Naming convention for package- com.projectname.packagename (com.CustomerCentre.Library)

All the methods related to Generic, we write them under GenericLibrary class which is present in the Libraries package.
And all the project specific methods are written under ProjectSpecificLibrary class which is present under libraries package.

All the GenericLibrary method should be public as well as static. Like – getLastRowNum, getCellValue, setCellValue, etc.

In the application there are certain types of steps which has to be used again & again such as open browser, open application & so on.
In order to handle these types of steps we create ConfigLibrary (SuperTestNG) class in which we have written the methods by using Selenium annotations
like @BeforeMethod, @AfterMethod etc. so that we need not to write the code for repeating steps each time. Inharit this class from all other classes to
use these class methods.

We create an excel file by name Config, in which we wrote all the input data for the testing and then copy the entire excel file,
and paste it under the CustomerCentre project.

To confirm everything working fine or not, we create a dummy package with dummy @Test method. If browser is getting launched, app is getting
launched & browser is getting closed i.e. whatever we have developed till is correct. Then delete the dummy package.
To perform the validation, we create one more class Assertion. Whenever we need to perform validation we need to call assertText() or assertTitle() present
under the Assertion class. (Assert.assertEquals())

2)- Implementing the ProjectSpecificLibrary-

This is where actual implementation of the framework start. While going thru the manual testcases we note down the common repeated steps
and make those steps as a project specific methods. Even if one step is repeating , may be in same testcase or other testcase make it as a method.
Then write the test script for all the manual test cases.

3)- Execution-

Right click on the project, navigate to TestNG ? convert to TestNG ? give the proper suite name and test name and click on finish.
Then execute this xml file (ctrl+f11) or right click and run as TestNG Suite.
to run thru cmd ? navigate till project then give this commnd-
java -cp bin;jars/* org.testng.TestNG testng.xml



4. What is // and / in xpath

//  (double slash ) Is the Relative xPath
Relative path will from current path (//)
Relative xPath : //h3/a[text()='Working on New Window']

/ (Single slash) Is the Absolute xPath
Absolute path will start with root path (/) and Relative path will from current path (//)

Absolute xPath
: /html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div[@id='main']/div[@id='Blog1']/div[1]/div[1]/div/div[1]/div/h3/a


5.  which selenium version ur working

version : 2.42.2


6.  How do find the xpath?

Using Firebug and Firepath.


9.   What is Selenium IDE?

Selenium IDE is an integrated development environment for Selenium scripts.
It is implemented as a Firefox extension, and allows you to record, edit, and debug tests.


10. What is Selenium Webdriver?

Selenium-WebDriver makes direct calls to the browser using each browser's native support for automation.
 It simulates user interaction with the browser such as typing and clicking by calling native methods of the browser.


11.    Have you used TestNG?

 Yes.

12.    What is annotations?


TestNG annotations:

 @Test,@Parameters,@Listeners,@BeforeSuite,@AfterSuite,@BeforeTest,@AfterTest,
 @DataProvider,@BeforeGroups,@AfterGroups,@BeforeClass,@AfterClass,
 @BeforeMethod,@AfterMethod,@Factory


14.  How do you handle popups.


7 types of pop-up:

Alert popup- First we need to transfer the controll to the alert pop-up and then we should perform the operation.
  
driver.SwitchTo().alert();

Hidden Division pop-up(HDP)- In order to handle this popup we use find element method.

File upload pop-up- in order to handle this popup we specify the complete path of the file as argument

for send keys method.

File download popup- To handle this pop up we use Set preference method firefox profile.

Child Browser pop-up- we use iterator() , hasNext() and next method.

Page on load popup- In order to handle this give username and password in the url itself.
  
some browser does not support username and password in url. in tat case use AutoIT.

Window Pop-UP- Using AutoIT or Robot class of java awt package.


15.  What is the use of Xpath?

To locate the elements.


16. Different types of locators?

Types of lacators:

1. Tag Name
2. Id
3. Name
4. class Name
5. Link text
6. Partial Linktext
7. CSS Selector.
8. xpath.

17.  Selenium Framework that you are using in your current project?


TestNG Framework.


18. How do you identify the Xpath of element on your browser?

Using Firebug and Firepath. In firepath if the given xpath expression is matching with one element its correct.


19. Selenium function used for retrieving the attribute or value?

getAttribute() and getText() methods


20.    How do you differentiate check box if more than one check box is existed in your application?

 int count= all checkBoxes.Size();
 sop(count);
21.    Difference between Assert and Verify?
Assert command in selenium:

When an "assert" command fails then test execution will be aborted.
Assert is best used when the check value has to pass for the test to be able to continue to run. Like a log in.


Verify command in selenium:

When a "verify" command fails then test will continue executing and logging the failure.


22.    What is the alternate way to click on login button?

driver.findElement(By.name("submit")).sendKeys(Keys.Return);
or

driver.findElement(By.name("submit")).sendKeys(Keys.Enter);
Verify is best used to check non critical things. Like hte presence of a headline element.


23.    How do you verify if the checkbox/radio is checked or not

// Store all the elements of same category in the list of WebLements   

 List  oRadioButton = driver.findElements(By.name("toolsqa"));

 // Create a boolean variable which will hold the value (True/False)

 boolean bValue = false;

 // This statement will return True, in case of first Radio button is selected

 bValue = oRadioButton.get(0).isSelected();

 // This will check that if the bValue is True means if the first radio button is selected

 if(bValue = true){

    // This will select Second radio button, if the first radio button is selected by default

    oRadioButton.get(1).click();

 }else{

    // If the first radio button is not selected by default, the first will be selected

    oRadioButton.get(0).click();

24.    How to get the href of a link / get the source of image

final List<WebElement> allLinks = driver.findElements(By.tagName("a"));
for (final WebElement link : allLinks) {
String orgLink = link.getAttribute("href");
resultList.add(orgLink);

For Image:

driver.findElement(By.cssSelector("a[href='images/shim.gif']")).click();


25.    Count the number of links in a page

List<WebElement> foo = driver.findElements(By.tagName("a"));
int count =0;
for(WebElement element : foo){
count++;
System.out.println("Count:"+count);


26.    How to check all checkboxes in a page

List<WebElement> checkBoxList=driver.findElements(By.cssSelector("input [type='checkbox']"));
   
for(WebElement checkBox:checkBoxList)
    {
        checkBox.click();  
    }
}

27.    How do you handle browser popup?

By using window handle we can here is an example...
  
        WebDriver driver= new FirefoxDriver();
        driver.get("http://www.rediff.com/");
        WebElement sign = driver.findElement(By.xpath("//html/body/div[3]/div[3]/span[4]/span/a"));
        sign.click();

        Set<String> windowId = driver.getWindowHandles();    // get  window id of current window
        Iterator<String> itererator = windowId.iterator();  

        String mainWinID = itererator.next();
        String  newAdwinID = itererator.next();

        driver.switchTo().window(newAdwinID);
        System.out.println(driver.getTitle());
        Thread.sleep(3000);
        driver.close();

        driver.switchTo().window(mainWinID);
        System.out.println(driver.getTitle());
        Thread.sleep(2000);

        WebElement email_id= driver.findElement(By.xpath("//*[@id='c_uname']"));
        email_id.sendKeys("hi");
        Thread.sleep(5000);

        driver.close();
        driver.quit();

28. How do you handle elements present inside frame?

driver.switchTo().frame(driver.findElement(By.id("frameId")));
//do your stuff
driver.switchTo().defaultContent();


29. How do you handle Javascript alert/confirmation popup?
       
        driver.manage().window().maximize();

        driver.get("file:///C:/path/alerts.html");

 Thread.sleep(2000);

 driver.findElement(By.xpath("//button[@onclick='alertFunction()']")).click();

 Alert alert=driver.switchTo().alert();

 System.out.println(alert.getText());

 alert.accept();



30. How do you launch IE/chrome browser?

InternetExplorerDriver object should be created after the webdriver.ie.driver property is set

System.setProperty("webdriver.ie.driver", "D:\\Eclipse Workspace\\Multi Browser\\IEDriverServer.exe");

WebDriver obj = new InternetExplorerDriver();
obj.get("http://www.google.com/");
obj.close();

31.  How to perform right click using WebDriver?

 WebElement elementq = driver.findElement(By.tagName("img"));
 Actions builderq = new Actions(driver);
 Action rClick = builderq.contextClick(elementq).build();
 rClick.perform();

32.    How do perform drag and drop using WebDriver?

WebElement From = driver.findElement(By.xpath(".//*[@id='treebox1']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[4]/span"));

WebElement To = driver.findElement(By.xpath(".//*[@id='treebox2']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[1]/td[4]/span"));

Actions builder = new Actions(driver);

Action dragAndDrop = builder.clickAndHold(From).moveToElement(To).release(To).build();

dragAndDrop.perform();


33.    How to send ENTER/TAB keys in WebDriver?


driver.findElement(By.name("submit")).sendKeys(Keys.Return);


34.    Example for method overload in WebDriver


35.    How do you upload a file?

We can upload by three ways

1. Use Robot class
2. Use AutoIt
3. Give the file path :

 WebElement UploadImg = driver.findElement(By.xpath("//*[@id='file_upload_button']"));
 
UploadImg.click();
 
WebElement frame =driver.switchTo().activeElement();

frame.sendKeys("d:\5.jpg");

36.    How do you click on a menu item in a drop down menu?

        WebElement element = driver.findElement(By.linkText("link"));

        Actions action = new Actions(driver);

        action.moveToElement(element).perform();

        WebElement subElement = driver.findElement(By.linkText("link to be clicked"));

        action.moveToElement(subElement);

        action.click();
        action.perform();

or

If that menu has been created by using select tag then we can use the methods selectByValue() or selectByIndex() or selectByVisibleText().
These are the methods of the Select class.

If the menu has not been created by using the select tag then we can simply find the xpath of that element and click on that to select.


37.    How do you work with page onload authentication popup / windows based popup?


pass the username and password with url.


38.  How do you simulate browser back and forward?

 driver.navigate().back();

 driver.navigate().forward();


39.    How do you get the current page URL?

driver.getCurrentUrl();


40.    What is an xpath?

it is used to find the WebElement in web page. It is very useful to identify the dynamic web elements.
41.    What is the difference between ‘/’ and ‘//’ ?

//- it is used to search in the entire structure.

/- it is used to identify the immediate child.


42.    What is the difference between findElement and findElements?

Both methods are abstract method of WebDriver interface and used to find the WebElement in a web page.

findElement() – it used to find the one web element. It return only one WebElement type.

findElements()- it used to find more than one web element. It return List of WebElements.


43.    How do you achieve synchronization in WebDriver?

We can use implicit wait.

Syntax- driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

Here it will wait for 10sec if while execution driver did not find the element in the page immediately. This code will
attach with each and every line of the script automatically. It is not required to write every time. Just write it once after opening the browser.


44.    Explain implicit and explicit wait?

Implicit Wait: During Implicit wait if the Web Driver cannot find it immediately because of its availability, the WebDriver will wait for
mentioned time and it will not try to find the element again during the specified time period. Once the specified time is over, it will try
to search the element once again the last time before throwing exception. The default setting is zero. Once we set a time, the Web Driver waits
for the period of the WebDriver object instance.

Explicit Wait: There can be instance when a particular element takes more than a minute to load. In that case you definitely not
like to set a huge time to Implicit wait, as if you do this your browser will going to wait for the same time for every element.

To avoid that situation you can simply put a separate time on the required element only. By following this your browser implicit
wait time would be short for every element and it would be large for specific element.

WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement")));


45.    Write the code for Reading and Writing to Excel through Selenium?


FileInputStream fis = new FileInputStream(“path of excel file”);

 Workbook wb = WorkbookFactory.create(fis);

 Sheet s = wb.getSheet("sheetName");

 String value = s.getRow(rowNum).getCell(cellNum).getStringCellValue(); // read data

 s.getRow(rowNum).getCell(cellNum).setCellValue("value to be set"); //write data

 FileOutputStream fos = new FileOutputStream(“path of file”);

 wb.write(fos); //save file


46.    How do get typed text from a textbox?


use getAttribute(“value”) method by passing arg as value.

String typedText = driver.findElement(By.xpath("xpath of box")).getAttribute("value"));


47.    What are the different exceptions you get when working with WebDriver?

ElementNotVisibleException, ElementNotSelectableException, NoAlertPresentException, NoSuchAttributeException,
NoSuchWindowException, TimeoutException, WebDriverException etc.


48.    What are the languages supported by WebDriver?

Python, Ruby, C# and Java are all supported directly by the development team. There are also webdriver implementations for PHP and Perl.


49.    What are the limitations of Selenium IDE?


It does not supports looping or conditional statements. Tester has to use native languages to write logic in the test case.
It does not supports test reporting, you have to use selenium RC with some external reporting pligin like TestNG or JUint to get test execution report.
Error handling is also not supported depending on the native language for this.


50.    What are the browsers supported by Selenium IDE?

Firefox


51.    How do you clear the contents of a textbox in selenium?

by using clear() method

driver.findElement(By.xpath("xpath of box")).clear();


52.    What is a Framework?

A framework is set of automation guidelines which help in

Maintaining consistency of Testing, Improves test structuring, Minimum usage of code, Less Maintenance of code, Improve re-usability,
Non Technical testers can be involved in code, Training period of using the tool can be reduced, Involves Data wherever appropriate.

There are five types of framework used in software automation testing:

1-Data Driven Automation Framework

2-Method Driven Automation Framework

3-Modular Automation Framework

4-Keyword Driven Automation Framework

5-Hybrid Automation Framework , its basically combination of different frameworks. (1+2+3).


53.    Different components of your framework?
54.    Can you explain the Framework flow with a diagram
55.    How do you accommodate project specific methods in your framework?
56.    How is the failure handled in your framework?



57.    What kind of reports are generated by your framework?

XSLL using TestNG+ANT

Explain your framework which exactly u r using .....


58.    What are the prerequisites to run selenium webdriver?

JDK, Eclipse, WebDriver(selenium standalone jar file), browser, application to be tested.



59.    What are the advantages of selenium webdriver?

a) It supports with most of the browsers like Firefox, IE, Chrome, Safari, Opera etc.

b) It supports with most of the language like Java, Python, Ruby, C# etc.

b) Doesn’t require to start server before executing the test script.

c) It has actual core API which has binding in a range of languages.

d) It supports of moving mouse cursors.

e) It support to test iphone/Android applications.


60.    What is webdriver backed selenium?


 WebDriverBackedSelenium is a kind of class name where we can create an object for it as below:


Selenium wbdriver= new WebDriverBackedSelenium(WebDriver object name, "URL path of website")

The main use of this is when we want to write code using both WebDriver and Selenium RC , we must use above created object to use selenium commands.
61.    How to invoke an application in webdriver?


driver.get(“url”); or driver.navigate().to(“url”);


62.    What is Selenium Grid?

Selenium-Grid allows you to run your tests on different machines against different browsers in parallel. That is,
running multiple tests at the same time against different machines, different browsers and operating systems. Essentially,
Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.


63.    How to get the number of frames on a page?


List &lt;WebElement&gt; framesList = driver.findElements(By.xpath("//iframe"));

 int numOfFrames = frameList.size();

 S.o.P.(numOfFrames);


64.    How to verify that an element is not present on a page?

use isDisplayed() method. The return type of the method is boolean. So if it return true then element is visible else not visible.

driver.findElement(By.xpath("xpath of elemnt")).isDisplayed();


65.    How do you simulate scroll down action?

Use java script to scroll down-


  JavascriptExecutor jsx = (JavascriptExecutor)driver;

 jsx.executeScript("window.scrollBy(0,4500)", ""); //scroll down, value 4500 you can change as per your req

 jsx.executeScript("window.scrollBy(450,0)", ""); //scroll up

 ex-

 public class ScrollDown {

 public static void main(String[] args) throws InterruptedException {

 WebDriver driver = new FirefoxDriver();

 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

 driver.get("http://www.flipkart.com/womens-clothing/pr?sid=2oq,c1r&amp;otracker=hp_nmenu_sub_women_1_View%20all");

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

 JavascriptExecutor jsx = (JavascriptExecutor)driver;

 jsx.executeScript("window.scrollBy(0,4500)", ""); //scroll down

 Thread.sleep(3000);

 jsx.executeScript("window.scrollBy(450,0)", ""); //scroll up

 }

 }


66.    What is Robot class?

Robot Class is available under java.awt package. Using this Robot Class we can simulate keyboard events in Selenium.


67.    How do you verify that the given list of numbers on a web page is sorted in ascending order?

get a List<E> from the WebElements, put the String values into (I think) a SortedList<String>.  I was playing around with it after doing some
googling for the right classes.  You add each string to the sorted list and pull it out using an iterator method until the next method returns false. 

I may have that class name wrong and I am not sure what happens with it if you have duplicated entries (which I will).

Take a look with Google for some examples.  I started with the Sort class and moved on to look at others.


68.    How to verify the presence of the success message on a page?

By using assertion we can get the text and can compare it with expected text


69.    Which  is the package which is to be imported while working with webdriver?

org.openqa.selenium
org.openqa.selenium.WebDriver;



70.    How to check if an element is visible on the web page?


use isDisplayed() method. The return type of the method is boolean. So if it return true then element is visible else not visible.

driver.findElement(By.xpath("xpath of elemnt")).isDisplayed();


71.    How to check if a button is enabled on the page?

Use isEnabled() method. The return type of the method is boolean. So if it return true then button is enabled else not enabled.

driver.findElement(By.xpath("xpath of button")).isEnabled();



72.    How to check if a text is highlighted on the page?

To identify weather color for a field is different or not-

String color = driver.findElement(By.xpath("//a[text()='Shop']")).getCssValue("color");

 String backcolor = driver.findElement(By.xpath("//a[text()='Shop']")).getCssValue("background-color");

 System.out.println(color);

 System.out.println(backcolor);


73.    What is the selenium's recording language?

Selenium IDE is a firefox plugin that gives you a basic recorder for recording tests. These tests are recorded in an HTML
table based architecture using keywords, and IDE gives you the ability to then export
the code out to other languages (Java, .Net, PHP, Python, Ruby, or Perl).


74.    How do you handle Ajax controls using selenium?


The implicit wait in Selenium 2 might not work for Ajax elements. We recommend you to use any one of the following workaround to handle Ajax elements.

One approach is to use FluentWait and a Predicate available with Selenium2. The advantage of this approach is that element polling mechanism is configurable.
The code example below waits for 1 second and polls for a textarea every 100 milliseconds.

  
 FluentWait<By> fluentWait = new FluentWait<By>(By.tagName("TEXTAREA"));
        fluentWait.pollingEvery(100, TimeUnit.MILLISECONDS);
        fluentWait.withTimeout(1000, TimeUnit.MILLISECONDS);
        fluentWait.until(new Predicate<By>() {
            public boolean apply(By by) {
                try {
                    return browser.findElement(by).isDisplayed();
                } catch (NoSuchElementException ex) {
                    return false;
                }
            }
        });
      
 browser.findElement(By.tagName("TEXTAREA")).sendKeys("text to enter");


75.    How to check the checkbox or radio button is selected?

Use isSelected() method to identify. The return type of the method is boolean. So if it return true then button is selected else not enabled.

driver.findElement(By.xpath("xpath of button")).isSelected();
   


76.    How to get the title of the page?

Use getTitle() method.

driver.getTitle();


77.    How do u get the width of the textbox?


driver.findElement(By.xpath(“xpath of textbox ”)).getSize().getWidth();

driver.findElement(By.xpath(“xpath of textbox ”)).getSize().getHeight();


78.    How do u get the attribute value of the web element?

driver.getElement(By.tagName(“img”)).getAttribute(“src”) will give you the src attribute of this tag. Similarly,
you can get the values of attributes such as title, alt etc.

Similarly you can get CSS properties of any tag by using getCssValue(“some propety name”).


79.    How to check whether a text is underlined or not?


Identify by getCssValue(“border-bottom”) or sometime getCssValue(“text-decoration”) method if the

 cssValue is 'underline' for that WebElement or not.

 ex- This is for when moving cursor over element that is going to be underlined or not-

 public class UnderLine {

 public static void main(String[] args) {

 WebDriver driver = new FirefoxDriver();

 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

 driver.get("https://www.google.co.in/?gfe_rd=ctrl&amp;ei=bXAwU8jYN4W6iAf8zIDgDA&amp;gws_rd=cr");

 String cssValue= driver.findElement(By.xpath("//a[text()='Hindi']")).getCssValue("text-decoration");

 System.out.println("value"+cssValue);

 Actions act = new Actions(driver);

 act.moveToElement(driver.findElement(By.xpath("//a[text()='Hindi']"))).perform();

 String cssValue1= driver.findElement(By.xpath("//a[text()='Hindi']")).getCssValue("text-decoration");

 System.out.println("value over"+cssValue1);

 driver.close();

 }

 }



80.    How to change the URL on a webpage using selenium web driver?

driver.get(“url1”);

driver.get(“url2”);
81.    How to verify the presence of tooltips for a link?

WebElement element = driver.FindElement(By.id("divTooltips");
string titleText = element.getAttribute("title");

now title is stored in titleText string .

or

Whenever you will have tooltip then "title" attribute will be there. (as per my observation ).

for example: Goto http://www.linkedin.com/ and view HTML code for LinkedIn image on top. LinkedIn

    WebDriver driver = new InternetExplorerDriver();
    driver.get("http://www.linkedin.com/");
    WebElement onElement = driver.findElement(By.xpath("html/body/div[1]/div[1]/div/h2/a"));
    System.out.println("Tooltip : " + onElement.getAttribute("title"));


82.    How to hover the mouse on an element?

Actions act = new Actions(driver);

act.moveToElement(webelement); //webelement on which you want to move cursor.


83.    What is the use of getOptions() method?

getOptions() is used to get the selected option from the dropdown list.


84.    What is the use of deSelectAll() method?

t is used to deselect all the options which have been selected from the dropdown list.


85.    Is WebElement an interface or a class?

WebDriver is an Interface.


86.    FirefoxDriver is class or an interface and from where is it inherited?

FirefoxDriver is a class. It implements all the methods of WebDriver interface.


87.    Which is the super interface of webdriver?

SearchContext.


88.    What is the difference b/w close() and quit()?

close() – it will close the browser where the control is.

quit() – it will close all the browsers opened by WebDriver.


89.    What is the difference b/w getWindowHandles() and getWindowHandle() ?


getWindowHandles()- is used to get the address of all the open browser and its return type is Iterator<String>.

getWindowHandle()- is used to get the address of the current browser where the conrol is and return type is String.


90.    What is the use of contextClick() ;

It is used to right click.


92.    How to perform double click using webdriver?

use doubleClick() method.


93.    What is the use of AutoIt?

Some times while doing testing with selenium, we get stuck by some interruptions like a window based pop up.
But selenium fails to handle this as it has support for only web based application. To overcome this problem we need to
use AutoIT along with selenium script. AutoIT is a third party tool to handle window based applications. The scripting language used is in VBScript.


94.    How to type text in a new line inside a text area?

Use \n for new line.

ex- webelement.sendKeys(“Sanjay_Line1.\n Sanjay_Line2.”);
it will type in text box as-

Sanjay_Line1.

Sanjay_Line2.


95.    How to switch back from a frame?

use method defaultContent().


96.    What is the use of getPageSource()?

it fetch all the source of a specific webpage and that can be user to verify the text on the page



97.    Can you handle flash using web driver?

Flash objects are impossible to automate using Selenium as flash objects are not technically 'browser driven' like javascript is.
You'll have to find other software to automate Flash.


98.    How do you send ENTER/TAB keys in webdriver?

use click() or submit() [submit() can be used only when type='submit']) method for ENTER. Or use Actions class to press keys.

For Enter-

act.sendKeys(Keys.RETURN);
For Tab-

act.sendKeys(Keys.ENTER);
where act is Actions class type. ( Actions act = new Actions(driver); )


100.    What is the benefit of using TestNG?

1.In TestNG Annotations are easy to understand over JUnit.
2.In TestNG there is no constraint like you have to declare @BeforeClass and @AfterClass, which is present in JUnit.
3.As method name constraint is present in JUnit, such method name constraint is not present in TestNG and you can specify any test method names.
4.In TestNG enable you to grouping of test cases easily which is not possible in JUnit.
5.TestNG supports following three 3 additional setUp/tearDown level:
6.@Before/AfterSuite, @Before/AfterTest and @Before/AfterGroup.
7.TestNG do not require extend any class.
8.TestNG allows us to define the dependent test cases each test case is independent to other test case.
9.TestNG allows us to execute of test cases based on group. Let’s take a scenario where we have created two set of groups “Regression” & “Sanity”.
If we want to execute the test cases under Sanity group then it is possible in TestNG framework.
10.Parallel execution of Selenium test cases is possible in TestNG.


Source: Taken from Skype chat of selenium group.