Thursday, 16 March 2023

selenium interview questions

 1. handle dynamic web elements in Selenium

  • use relative xpath or css selector
  • identify element based on surrounding elements
  • dynamic locator, e.g. contains(), startwith(), regex

2. assert vs. verify
  • verify does not stop the execution

3. handle popup, tab, window
  • get the handle, then switch to

4. upload and download
  • upload: sendkey() with filepath, or use AutoIT or Robot class
  • download: set some preferences, click download link

5. cookies
  • getCookies()
  • addCookie()
  • deleteCookie()

6. implicit wait, explicit wait, fluent wait
  • use explicit wait instead of implicit wait, DO NOT mix them together at same time
  • implicit wait poll the DOM for specified amount of time before trying to locate element
  • implicit wait is disabled by default and need to be enabled
  • explicit wait wait for certain condition to happen
  • fluent wait is a customised explicit wait

7. action
  • mouse and keyboard actions
  • mouse: doubleClick(), clickAndHold(), dragAndDrop(), moveToElement(), contextClick()
  • keyboard: sendKeys(), keyUp(), keyDown()

8. driver close vs quit
  • close: close current window
  • quit: quit session

9. alert and popup
  • alert: switchTo().alert()..dismiss()/.accept()/.sendKeys()

10. account login
  • navigate to login page
  • use api call to get auth token, then set browser cookie
  • refresh page, or navigate to the after-login page

11. selenium grid
  • hub is an instance of selenium server with config to distribute test
  • node is an instance of selenium server with browser capabilities that the node supports

12. handle iframe


reference




No comments:

Post a Comment