Selenium Interview Questions with Answers (Coding based)
Question Question How do you take a screenshot in Selenium?
Answer File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("screenshots/error.png")); Use TakeScreenshot Interface, typecasted to driver instance. 1. Copy Taken screen shot to any file on hard drive.
Question How do you simulate mouse operations in Selenium?
Answer To simulate mouse operations in Selenium, • Choose Actions class under selenium > operations package. Ii is used for mouse operations. It is a a user-facing API for emulating complex user gestures. • Selenium recommends use of this class for Mouse operations. • It implements the builder pattern: Builds a Composite Action containing all actions specified by the method calls.
Question How to select drop down values in Selenium? Approaches to select drop down?
Answer We use Select class under selenium > support > ui package to select and deselect in a dropdown list box. There are multiple approaches to do so as mentioned: Approaches 1. selectByIndex(int index) Select the option at the given index. 2. selectByValue(java.lang.String value) Select all options that have a value matching the argument. 3. selectByVisibleText(java.lang.String text) Select all options that display text matching the argument.
Question How do you simulate Special Keys in Selenium like Ctrl , Alt etc.
Answer Enum Keys is used for this purpose. This is part of selenium package. Keys.chord(Keys.CONTROL,"c")).perform() The above code will simulate the behavior of CTRL + C
Question Tell me how do you work with multiple windows in Selenium?
Answer Some web applications have many frames or multiple windows. WebDriver supports moving between named windows using the “switchTo” method: driver.switchTo().window("windowName"); You can pass a “window handle” to the “switchTo().window()” method. Knowing this, it’s possible to iterate over every open window like so: for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); }
Question How do you handle HTML Tables in Selenium?
Answer 1.’table’ tag defines html table. 2.’tbody’ tag defines container for rows and columns. 3.’tr’ defines rows in an html table. 4.’td’/’th’ define column of an html table. Use tagname locator strategy to identify and extract data
Question Which is the most effective locator strategy in Selenium?
Answer CSS works with simple attributes like ID and Class, XPATH will traverse the DOM top down to work with nested elements, so CSS is faster CSS are clear and concise. Also Selectors are more readable.
16 THANKS! Any questions? You can contact us at ▪ info@techcanvass.com ▪ 022-40155 175 ▪ 7738 7731 08 www.techcanvass.com

Selenium Interview Questions & Answers

  • 1.
    Selenium Interview Questionswith Answers (Coding based)
  • 2.
    Question Question How do youtake a screenshot in Selenium?
  • 3.
    Answer File src =((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("screenshots/error.png")); Use TakeScreenshot Interface, typecasted to driver instance. 1. Copy Taken screen shot to any file on hard drive.
  • 4.
    Question How do yousimulate mouse operations in Selenium?
  • 5.
    Answer To simulate mouseoperations in Selenium, • Choose Actions class under selenium > operations package. Ii is used for mouse operations. It is a a user-facing API for emulating complex user gestures. • Selenium recommends use of this class for Mouse operations. • It implements the builder pattern: Builds a Composite Action containing all actions specified by the method calls.
  • 6.
    Question How to selectdrop down values in Selenium? Approaches to select drop down?
  • 7.
    Answer We use Selectclass under selenium > support > ui package to select and deselect in a dropdown list box. There are multiple approaches to do so as mentioned: Approaches 1. selectByIndex(int index) Select the option at the given index. 2. selectByValue(java.lang.String value) Select all options that have a value matching the argument. 3. selectByVisibleText(java.lang.String text) Select all options that display text matching the argument.
  • 8.
    Question How do yousimulate Special Keys in Selenium like Ctrl , Alt etc.
  • 9.
    Answer Enum Keys isused for this purpose. This is part of selenium package. Keys.chord(Keys.CONTROL,"c")).perform() The above code will simulate the behavior of CTRL + C
  • 10.
    Question Tell me howdo you work with multiple windows in Selenium?
  • 11.
    Answer Some web applicationshave many frames or multiple windows. WebDriver supports moving between named windows using the “switchTo” method: driver.switchTo().window("windowName"); You can pass a “window handle” to the “switchTo().window()” method. Knowing this, it’s possible to iterate over every open window like so: for (String handle : driver.getWindowHandles()) { driver.switchTo().window(handle); }
  • 12.
    Question How do youhandle HTML Tables in Selenium?
  • 13.
    Answer 1.’table’ tag defineshtml table. 2.’tbody’ tag defines container for rows and columns. 3.’tr’ defines rows in an html table. 4.’td’/’th’ define column of an html table. Use tagname locator strategy to identify and extract data
  • 14.
    Question Which is themost effective locator strategy in Selenium?
  • 15.
    Answer CSS works withsimple attributes like ID and Class, XPATH will traverse the DOM top down to work with nested elements, so CSS is faster CSS are clear and concise. Also Selectors are more readable.
  • 16.
    16 THANKS! Any questions? You cancontact us at ▪ info@techcanvass.com ▪ 022-40155 175 ▪ 7738 7731 08 www.techcanvass.com