Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Selenium Interview Questions and Answers

Ques 31. Write a code snippet to launch Chrome browser in WebDriver.

public class ChromeBrowserLaunchDemo {  
  
  public static void main(String[] args) {  
  
    //Creating a driver object referencing WebDriver interface  
    WebDriver driver;  
  
    //Setting the webdriver.chrome.driver property to its executable's location  
    System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");  
      
    //Instantiating driver object  
    driver = newChromeDriver();  
  
    //Using get() method to open a webpage  
    driver.get("http://javatpoint.com");  
  
    //Closing the browser  
    driver.quit();  
  
  }  
}  

Is it helpful? Add Comment View Comments
 

Ques 32. Write a code snippet to launch Internet Explorer browser in WebDriver.

public class IEBrowserLaunchDemo {  
  
  public static void main(String[] args) {  
  
    //Creating a driver object referencing WebDriver interface  
    WebDriver driver;  
  
    //Setting the webdriver.ie.driver property to its executable's location  
    System.setProperty("webdriver.ie.driver", "/lib/IEDriverServer/IEDriverServer.exe");  
      
    //Instantiating driver object  
    driver = newInternetExplorerDriver();  
  
    //Using get() method to open a webpage  
    driver.get("http://javatpoint.com");  
  
    //Closing the browser  
    driver.quit();  
  
  }  
  
}  

Is it helpful? Add Comment View Comments
 

Ques 33. Write a code snippet to perform right-click an element in WebDriver.

We will use Action class to generate user event like right-click an element in WebDriver.

Actions action = newActions(driver);  

WebElement element = driver.findElement(By.id("elementId"));  

action.contextClick(element).perform();  

Is it helpful? Add Comment View Comments
 

Ques 34. Write a code snippet to perform mouse hover in WebDriver.

Actions action = newActions(driver);  

WebElement element = driver.findElement(By.id("elementId"));  

action.moveToElement(element).perform();  

Is it helpful? Add Comment View Comments
 

Ques 35. How do you perform drag and drop operation in WebDriver?

Code snippet to perform drag and drop operation:

//WebElement on which drag and drop operation needs to be performed  

WebElementfromWebElement = driver.findElement(By Locator of fromWebElement);  

 

//WebElement to which the above object is dropped  

WebElementtoWebElement = driver.findElement(By Locator of toWebElement);  

  

//Creating object of Actions class to build composite actions  

Actions builder = newActions(driver);  

  

//Building a drag and drop action  

Action dragAndDrop = builder.clickAndHold(fromWebElement)  

             .moveToElement(toWebElement)  

             .release(toWebElement)  

         .build();  

  

//Performing the drag and drop action  

dragAndDrop.perform();  

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook