Quiz With Answers 5

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Which programming language is commonly used for Selenium automation?

a) Java

b) Python

c) C#

d) JavaScript

Answer: a) Java

How can you locate an element by its ID in Selenium WebDriver?

a) By using the By.tagName("tagname") locator

b) By using the By.className("classname") locator

c) By using the By.xpath("xpathExpression") locator

d) By using the By.id("elementId") locator

Answer: d) By using the By.id("elementId") locator

How can you maximize the browser window in Selenium WebDriver?

a) By using the driver.manage().window().setSize() method

b) By using the driver.manage().window().fullscreen() method

c) By using the driver.manage().window().maximize() method

d) By using the driver.manage().window().minimize() method

Answer: c) By using the driver.manage().window().maximize() method

How can you handle dropdowns in Selenium WebDriver?

a) By using the driver.findElement(By.id("dropdownId")).click(); method

b) By using the driver.findElement(By.id("dropdownId")).sendKeys("option"); method

c) By using the Select class and its methods like selectByVisibleText(), selectByValue(), or selectByIndex()
d) By using the driver.switchTo().frame("frameName"); method

Answer: c) By using the Select class and its methods like selectByVisibleText(), selectByValue(), or
selectByIndex()

How can you handle alerts in Selenium WebDriver?

a) By using the driver.switchTo().defaultContent(); method

b) By using the driver.switchTo().alert() method to switch to the alert and then using methods like
accept(), dismiss(), or getText()

c) By using the driver.findElement(By.id("alertId")).click(); method

d) By using the driver.findElement(By.id("alertId")).sendKeys("text"); method

Answer: b) By using the driver.switchTo().alert() method to switch to the alert and then using methods
like accept(), dismiss(), or getText()

What is the correct way to wait for an element to be visible in Selenium WebDriver?

a) By using explicit waits with the ExpectedConditions.visibilityOfElementLocated() method

b) By using implicit waits with the driver.manage().timeouts().implicitlyWait() method

c) By using fluent waits with the Wait interface and its methods like until()

d) By using conditional statements like if and else to check the visibility of the element

Answer: a) By using explicit waits with the ExpectedConditions.visibilityOfElementLocated() method

How can you perform a right-click action in Selenium WebDriver?

a) By using the driver.rightClick(element); method

b) By using the Actions class and its methods like contextClick(element).perform();

c) By using the driver.contextClick(element); method

d) Right-click actions are not supported in Selenium WebDriver

Answer: b) By using the Actions class and its methods like contextClick(element).perform();
How can you handle multiple windows or tabs in Selenium WebDriver?

a) By using the driver.switchTo().window(windowHandle); method

b) By using the driver.getWindowHandles() method to get all window handles and then switching to the
desired window by handle

c) By using the driver.getWindowHandle() method to get the current window handle and then switching
to the desired window

d) By using the driver.switchTo().frame("frameName"); method

Answer: b) By using the driver.getWindowHandles() method to get all window handles and then
switching to the desired window by handle

How can you perform keyboard actions like pressing Enter or typing text in Selenium WebDriver?

a) By using the Actions class and its methods like sendKeys(Keys.ENTER) or sendKeys("text")

b) By using the driver.keyboard().pressKey(Keys.ENTER) method

c) By using the driver.sendKeys(Keys.ENTER) method

d) Keyboard actions are not supported in Selenium WebDriver

Answer: a) By using the Actions class and its methods like sendKeys(Keys.ENTER) or sendKeys("text")

How can you capture screenshots in Selenium WebDriver?

a) By using the driver.captureScreenshot("path/to/screenshot.png"); method

b) By using the driver.getScreenshotAs(OutputType.FILE) method and saving the file

c) By using the driver.takeScreenshot("path/to/screenshot.png"); method

d) Selenium WebDriver does not support capturing screenshots

Answer: b) By using the driver.getScreenshotAs(OutputType.FILE) method and saving the file

How can you handle frames in Selenium WebDriver?

a) By using the driver.switchTo().frame(frameIndex); method

b) By using the driver.switchTo().frame(frameElement); method


c) By using the driver.switchTo().defaultContent(); method to switch back to the main frame

d) All of the above

Answer: d) All of the above

How can you simulate mouse hover actions in Selenium WebDriver?

a) By using the driver.hover(element); method

b) By using the Actions class and its methods like moveToElement(element).perform();

c) By using the driver.moveToElement(element); method

d) Mouse hover actions are not supported in Selenium WebDriver

Answer: b) By using the Actions class and its methods like moveToElement(element).perform();

How can you execute JavaScript code in Selenium WebDriver?

a) By using the driver.executeScript("javascript code"); method

b) By using the driver.runScript("javascript code"); method

c) By using the driver.executeJavaScript("javascript code"); method

d) JavaScript code cannot be executed in Selenium WebDriver

Answer: a) By using the driver.executeScript("javascript code"); method

How can you handle browser cookies in Selenium WebDriver?

a) By using the driver.manage().addCookie(cookie); method

b) By using the driver.manage().deleteCookie(cookie); method

c) By using the driver.manage().getCookieNamed("cookieName"); method

d) All of the above

Answer: d) All of the above


How can you navigate back and forward in the browser using Selenium WebDriver?

a) By using the driver.back() and driver.forward() methods

b) By using the driver.navigate().back() and driver.navigate().forward() methods

c) By using the driver.navigateBack() and driver.navigateForward() methods

d) Navigation actions are not supported in Selenium WebDriver

Answer: b) By using the driver.navigate().back() and driver.navigate().forward() methods

How can you handle browser windows and tabs in Selenium WebDriver?

a) By using the driver.getWindowHandle() method to get the current window handle

b) By using the driver.switchTo().window(windowHandle); method to switch to a specific window

c) By using the driver.getWindowHandles() method to get all window handles

d) All of the above

Answer: d) All of the above

How can you simulate keyboard actions like pressing Esc or Ctrl+A in Selenium WebDriver?

a) By using the driver.keyboard().pressKey(Keys.ESCAPE) and


driver.keyboard().pressKey(Keys.chord(Keys.CONTROL, "a")) methods

b) By using the Actions class and its methods like sendKeys(Keys.ESCAPE) and
sendKeys(Keys.chord(Keys.CONTROL, "a")).perform();

c) By using the driver.sendKeys(Keys.ESCAPE) and driver.sendKeys(Keys.chord(Keys.CONTROL, "a"))


methods

d) Keyboard actions like pressing Esc or Ctrl+A are not supported in Selenium WebDriver

Answer: b) By using the Actions class and its methods like sendKeys(Keys.ESCAPE) and
sendKeys(Keys.chord(Keys.CONTROL, "a")).perform();

How can you handle file uploads in Selenium WebDriver?

a) By using the driver.findElement(By.id("uploadField")).sendKeys("path/to/file"); method


b) By using the driver.uploadFile("path/to/file", "uploadField"); method

c) By using the driver.switchTo().fileUpload("path/to/file"); method

d) File uploads are not supported in Selenium WebDriver

Answer: a) By using the driver.findElement(By.id("uploadField")).sendKeys("path/to/file"); method

How can you simulate mouse scrolling actions in Selenium WebDriver?

a) By using the driver.scroll(element); method

b) By using the Actions class and its methods like sendKeys(Keys.ARROW_DOWN) or


sendKeys(Keys.PAGE_DOWN)

c) By using the driver.scrollDown(element); method

d) Mouse scrolling actions are not supported in Selenium WebDriver

Answer: b) By using the Actions class and its methods like sendKeys(Keys.ARROW_DOWN) or
sendKeys(Keys.PAGE_DOWN)

You might also like