1: What is Selenium 2.0
Webdriver is open source automation tool for web application.
WebDriver is designed to provide a simpler, more concise programming interface
in addition to addressing some limitations in the Selenium-RC API.
2: What is
cost of webdriver, is this commercial or open source.
selenium is open source and free of cost.
3:How you
specify browser configurations with Selenium 2.0?
Following driver classes are used for browser configuration
AndroidDriver,
ChromeDriver,
EventFiringWebDriver,
FirefoxDriver,
HtmlUnitDriver,
InternetExplorerDriver,
IPhoneDriver,
IPhoneSimulatorDriver,
RemoteWebDriver
4: How is
Selenium 2.0 configuration different than Selenium 1.0?
In case of Selenium 1.0 you need Selenium jar file pertaining to
one library for example in case of java you need java client driver and also
Selenium server jar file. While with Selenium 2.0 you need language binding
(i.e. java, C# etc) and Selenium server jar if you are using Remote Control or
Remote WebDriver.
5: Can you
show me one code example of setting Selenium 2.0?
WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
driver.findElement(By.xpath("XPathLocator)).click();
6: Which web
driver implementation is fastest?
HTMLUnitDriver. Simple reason is HTMLUnitDriver does not execute
tests on browser but plain http request – response which is far quick than
launching a browser and executing tests. But then you may like to execute tests
on a real browser than something running behind the scenes
7: What all
different element locators are available with Selenium 2.0?
Selenium 2.0 uses same set of locators which are used by Selenium
1.0 – id, name, css, XPath but how Selenium 2.0 accesses them is different. In
case of Selenium 1.0 you don’t have to specify a different method for each
locator while in case of Selenium 2.0 there is a different method available to
use a different element locator. Selenium 2.0 uses following method to access
elements with id, name, css and XPath locator –
driver.findElement(By.id("HTMLid"));
driver.findElement(By.name("HTMLname"));
driver.findElement(By.cssSelector("cssLocator"));
driver.findElement(By. className ("ClassName”));
driver.findElement(By. linkText ("LinkText”));
driver.findElement(By. partialLinkText ("PartialLink”));
driver.findElement(By. tagName ("TagName”));
driver.findElement(By.xpath("XPathLocator));
8: How
do I submit a form using Selenium?
WebElement element =
driver.findElement(By.id("ElementID"));
element.submit();
9: How to
capture screen shot in Webdriver?
File file=
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("c:\\name.png"));
10: How do I
clear content of a text box in Selenium 2.0?
WebElement element = driver.findElement(By.id("ElementID"));
element .clear();
11: How
to execute java scripts function.
JavascriptExecutor js = (JavascriptExecutor) driver;
String title = (String) js.executeScript("pass your java
scripts");
12: How to
count total number of rows of a table using Selenium 2.0?
List <WebElement> rows =
driver.findElements(By.className("//table[@id='tableID']/tr"));
int numberOfRows = rows.size();
13:How to
capture page title using Selenium 2.0?
String title = driver.getTitle()
14:How to
store page source using Selenium 2.0?
String pagesource = driver.getPageSource();
15: How to
store current url using selenium 2.0?
String currentURL = driver.getCurrentUrl();
16: How to
assert text assert text of webpage using selenium 2.0?
WebElement element =
driver.findElement(By.id("ElementID"));
String text = element.getText();
Assert.assertEquals("Actual Text", text);
17: How to get
element attribute using Selenium 2.0?
WebElement element = driver.findElement(By.id("ElementID"));
String attributeValue = element.
getAttribute("AttributeName");
18:How to
double click on element using selenium 2.0?
WebElement element =
driver.findElement(By.id("ElementID"));
Actions builder = new Actions(driver);
builder.doubleClick(element).build().perform();
19: How to
perform drag and drop in selenium 2.0?
WebElement source =
driver.findElement(By.id("Source ElementID"));
WebElement destination =
driver.findElement(By.id("Target ElementID"));
Actions builder = new Actions(driver);
builder.dragAndDrop(source, destination ).perform();
20: How to
maximize window using selenium 2.0?
driver.manage().window().maximize();
21: How to
click on element?
WebElement element =
driver.findElement(By.id("ElementID"));
element.click();
21: How to
enter text into page element ?
WebElement element =
driver.findElement(By.id("ElementID")).sendKeys(Username);;
22: How to
handle drop down ?
selectByValue:
Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));
selectByValue.selectByValue(VALUE);
selectByVisibleText:
Select selectByVisibleText = new Select
(driver.findElement(By.id(“SelectID_Two”)));
selectByVisibleText.selectByVisibleText(TEXT);
selectByIndex:
Select selectByIndex = new
Select(driver.findElement(By.id(“SelectID_Three”)));
selectByIndex.selectByIndex(INDEX);
23: How can
you find if an element in displayed on the screen?
WebDriver facilitates the user with the following methods to check
the visibility of the web elements. These web elements can be buttons, drop
boxes, checkboxes, radio buttons, labels etc.
isDisplayed()
isSelected()
isEnabled()
Syntax:
isDisplayed():
boolean buttonPresence =
driver.findElement(By.id(ID)).isDisplayed();
isSelected():
boolean buttonSelected =
driver.findElement(By.id(ID)).isDisplayed();
isEnabled():
boolean searchIconEnabled =
driver.findElement(By.id(ID)).isEnabled();
24: What are
the different types of navigation commands?
Following are the navigation commands:
navigate().back() – The above command requires no parameters and
takes back the user to the previous webpage in the web browser’s history.
Sample code:
driver.navigate().back();
navigate().forward() – This command lets the user to navigate to the
next web page with reference to the browser’s history.
Sample code:
driver.navigate().forward();
navigate().refresh() – This command lets the user to refresh the
current web page there by reloading all the web elements.
Sample code:
driver.navigate().refresh();
navigate().to() – This command lets the user to launch a new web
browser window and navigate to the specified URL.
Sample code:
driver.navigate().to(“https://google.com”);
25: How to
click on a hyper link using linkText?
driver.findElement(By.linkText(“Google”)).click();
The command finds the element using link text and then click on
that element and thus the user would be re-directed to the corresponding page.
The above mentioned link can also be accessed by using the
following command.
driver.findElement(By.partialLinkText(“Goo”)).click();
The above command find the element based on the substring of the
link provided in the parenthesis and thus partialLinkText() finds the web
element with the specified substring and then clicks on it.
26: How to
handle frame in WebDriver?
An inline frame acronym as iframe is used to insert another
document with in the current HTML document or simply a web page into a web page
by enabling nesting.
#Select iframe by id
driver.switchTo().frame(“ID of the frame“);
#Locating iframe using tagName
driver.switchTo().frame(driver.findElements(By.tagName(“iframe”).get(0));
#Locating iframe using index
driver.switchTo().frame(0);
#Locating iframe using name
driver.switchTo().frame(“name of the frame”);
#Select Parent Window
driver.switchTo().defaultContent();
27: When do we
use findElement() and findElements()?
findElement(): findElement() is used to find the first element in
the current web page matching to the specified locator value. Take a note that
only first matching element would be fetched.
Syntax:
WebElement element =
driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
findElements(): findElements() is used to find all the elements in
the current web page matching to the specified locator value. Take a note that
all the matching elements would be fetched and stored in the list of
WebElements.
Syntax:
List <WebElement> elementList =
driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
28: What is
the difference between driver.close() and driver.quit command?
close(): WebDriver’s close() method closes the web browser window
that the user is currently working on or we can also say the window that is
being currently accessed by the WebDriver. The command neither requires any
parameter nor does is return any value.
quit(): Unlike close() method, quit() method closes down all the
windows that the program has opened. Same as close() method, the command
neither requires any parameter nor does is return any value.
29: Can
Selenium handle windows based pop up?
Selenium is an automation testing tool which supports only web
application testing. Therefore, windows pop up cannot be handled using
Selenium.
30: How can we
handle web based pop up?
WebDriver offers the users with a very efficient way to handle
these pop ups using Alert interface. There are the four methods that we would
be using along with the Alert interface.
void dismiss() – The accept() method clicks on the “Cancel” button
as soon as the pop up window appears.
void accept() – The accept() method clicks on the “Ok” button as
soon as the pop up window appears.
String getText() – The getText() method returns the text displayed
on the alert box.
void sendKeys(String stringToSend) – The sendKeys() method enters
the specified string pattern into the alert box.
Syntax:
// accepting javascript alert
Alert alert = driver.switchTo().alert();
alert.accept();
31: How to
mouse hover on a web element using WebDriver?
WebDriver offers a wide range of interaction utilities that the
user can exploit to automate mouse and keyboard events. Action Interface is one
such utility which simulates the single user interactions.
32: How to
retrieve css properties of an element?
The values of the css properties can be retrieved using a get()
method:
Syntax:
driver.findElement(By.id(“id“)).getCssValue(“name of css
attribute”);
driver.findElement(By.id(“id“)).getCssValue(“font-size”);
Please also cover about implicit and explicit wait in webdriver.
ReplyDeletehttp://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
Veera Please Go through Waits in Selenium Webdriver
DeleteYou can find More interview Questions on Selenium Webdriver Interview Questions
ReplyDelete