Basic Selenium Interview Question Part - 1

How to handle autocomplete box in web driver?

driver.findElement(By.id("your searchBox")).sendKeys("your partial keyword");
Thread.sleep(3000);
List< WebElement> listItems = driver.findElements(By.xpath("your list item locator"));
listItems.get(0).click();
driver.findElement(By.id("your searchButton")).click();

How to handle colors in web driver?

Use getCssValue(arg0) function to get the colors by sending 'color' string as an argument.
Example
String col = driver.findElement(By.id(locator)).getCssValue("color");

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);

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
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");

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.

In frame if no frame Id as well as no frame
name then which attribute I should consider
throughout our script.

You can go like this.....driver.findElements(By.xpath("//iframe"))...
Then it will return List of frames then switch to each and every frame and search for
the locator which you want then break the loop

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;};");

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();

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; } } }

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.

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.
findElement() :
Find the first element within the current page using the given "locating mechanism".
Returns a single WebElement.
Syntax: WebElement findElement(By by)
Ex:
driver.get("url");
WebElement widget = driver.findElement(By .xpath(".//*[@id='BlogArchive1_ArchiveList']"));
widget.click();
findElements() :
Find all elements within the current page using the given "locating mechanism".
Returns List of WebElements.
Syntax:
WebElement ullist = driver.findElement(By.className("posts"));
  List<WebElement> posts = ullist.findElements(By.tagName("li"));
  System.out.println("List of Posts are Below");
  for (int i = 0; i < posts.size(); i++) {
   String post = posts.get(i).findElement(By.tagName("a")).getText();

   System.out.println(post);
  }

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);

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

Name 5 different exceptions you had in
selenium web driver and mention what instance
you got it and how do you resolve it?

< !--[if !supportLists]-->· <!--[endif]-->WebDriverException
< !--[if !supportLists]-->· <!--[endif]-->NoAlertPresentException
< !--[if !supportLists]-->· <!--[endif]-->NoSuchWindowException
< !--[if !supportLists]-->· <!--[endif]-->NoSuchElementException
< !--[if !supportLists]-->· <!--[endif]-->TimeoutException

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.

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)", "");

public static void mouseClickByLocator( String cssLocator ) {
     String locator = cssLocator;
     WebElement el = driver.findElement( By.cssSelector( locator ) );
     Actions builder = new Actions(driver);
     builder.moveToElement( el ).click( el );
     builder.perform();
}




Comments

Popular posts from this blog

ExecuteFile Method vs LoadFunctionLibrary Method

Types In Descriptive Programming

Basic information about MAVEN