Selenium Interview Questions (Autosaved) - 1
Selenium Interview Questions (Autosaved) - 1
10. What is the difference between thread.Sleep()and selenium. Set Speed ("2000")?
If the application is taking time to load the page then we use selenium.waitforpageload("
"). This command is doesn’t wait upto the given time whenever the page load is
completed.
If the application is taking time to refresh the page, then we use Thread. Sleep ( ).it is a
standard wait it simply wait to the given time.
selenium.setSpeed
1. Takes a single argument in string format
Ex: selenium.setSpeed("2000") - will wait for 2 seconds
2. Runs each command in after setSpeed delay by the number of milliseconds mentioned in
set Speed.
thread.sleep
1. Takes a single argument in integer format
ex: thread. Sleep(2000) - will wait for 2 seconds
2. Waits for only once at the command given at sleep.
11. In what situation selenium finding element
get fails?
· Element loading issue
· Dynamic id of web element
12. What is the difference between "GET" and"NAVIGATE" to open a web page in
selenium web driver?
Get method will get a page to load or get page source or get text that's all whereas
navigate
will guide through the history like refresh, back, forward.For example if we want to move
forward and do some functionality and back to the home page this can be achieved
through navigate() only. driver.get will wait till the whole page gets loaded and
driver.navigate
will just redirect to that page and will not wait
13. Please tell me the difference b/w implicitly Wait and Explicit wait.
Implicit Wait sets internally a timeout that will be used for all consecutive Web Element
searches. It will try lookup the element again and again for the specified amount of time
before throwing a NoSuchElementException if the element could not have been found. It
does only this and can't be forced into anything else - it waits for elements to show up.
Explicit Wait or just Wait is a one-timer used by you for a particular search. It is more
extendible in the means that you can set it up to wait for any condition you might like.
Usually, you can use some of the prebuilt Expected Conditions to wait for elements to
become clickable, visible, invisible, etc., or just write your own condition that suits your
needs.
24. How can we get the font size, font color, font type used for a particular text on a web
page using Selenium web driver?
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-size);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-colour);
driver.findelement(By.Xpath("Xpath ").getcssvalue("font-type);
driver.findelement(By.Xpath("Xpath ").getcssvalue("background-colour);
25. How to run tests in multiple browser parallel? Is there any other option other than
selenium grid?
You create a class with a method something like this:
\\Now create YourClassName class and call extend the above class something like this
@Test
public class YourClassName extends LaunchBrowser{
public void gotoGoogle(){
driver.get(“http://www.google.com");
}
}
26. How to prepare Customized html Report usingTestNG in hybrid framework.
Below are the 3 ways:
• Junit: with the help of ANT.
• TestNG: using inbuilt default.html to get the HTML report. Also XST reports from ANT,
Selenium, TestNG combination.
• Using our own customized reports using XSL jar for converting XML content to HTML.
28. How the TestNG interacts with Selenium Core?Explain me steps and internal
architecture?"
What is TestNG?
So far we had been doing Selenium tests without generating a proper format for the test results.
From this point on, we shall tackle how to make these reports using a test framework called
TestNG.
TestNG is a testing framework that overcomes the limitations of another popular testing framework
called JUnit. The "NG" means "Next Generation". Most Selenium users use this more than JUnit
because of its advantages. There are so many features of TestNG, but we will only focus on the most
32. How to find broken images in a page using Selenium Web driver.
1. Get xpath and then using tag name; get all the links in the page
2. Click on each and every link in the page
3. In the target page title, look for 404/500 error.
How to find broken images in a page using Selenium
package programs;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
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.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
@BeforeTest
@Parameters({ "BROWSER" })
public void setup(String BROWSER) {
System.out.println("Browser: " + BROWSER);
if (BROWSER.equals("FF")) {
System.out.println("Firefox Browser is selected");
driver = new FirefoxDriver();
} else if (BROWSER.equals("IE")) {
System.out.println("Internet Explorer Browser is selected");
driver = new InternetExplorerDriver();
} else if (BROWSER.equals("HU")) {
System.out.println("Html Unit Browser is selected");
driver = new HtmlUnitDriver();
} else if (BROWSER.equals("CH")) {
System.out.println("Google chrome Browser is selected");
driver = new ChromeDriver();
}
}
@Test
public void testParallel() throws Exception {
driver.get("http://ruchi-myseleniumblog.blogspot.in/2013/12/100-selenium-interview-
questions.html");
}
}
38. How to get text from captcha image??
driver.findElement(By.xpath(".//*[@id='SkipCaptcha']")).click();
String attr = ie.findElement(By.xpath(".//*[@id='SkipCaptcha']")).getAttribute("value");
System.out.println("The value of the attribute 'Name' is " + attr);
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.
48. “Suppose developer changed the existing image tonew image with same xpath. Is test
case pass or fail?"
· Pass
49. How to handle network latency using selenium?
· Using driver.manage.pageLoadingtime for network latency
50. How does u handle dynamic elements without using xpath (with example?)
· By using classname or css.
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 thesetTimeout 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;};");
}
}
75. What is the default time for selenium Ide and webdriver?
Default timeout in selenium ide is 30 seconds.
93. How to know all the methods supported in web driverand its syntax.
· In Org.openqa.selenium package, web driver interface has all the main methods
that can
be used in Selenium Web driver
·
94. How do you create html test report from your test script?
• I would see below 3 ways:
• Junit: with the help of ANT.
• TestNG: using inbuilt default.html to get the HTML report. Also XLST reports from ANT,
Selenium, TestNG combination.
• Using our own customized reports using XSL jar for converting XML content to HTML.
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
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
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