MCQs on Image Handling Using Selenium Java
Which Selenium WebDriver method is used to find an image element by its src attribute?
a) driver.findElement(By.linkText("src"))
b) driver.findElement(By.tagName("img"))
c) driver.findElement(By.xpath("//img[@src='image.jpg']"))
d) driver.findElement(By.cssSelector("src"))
Answer: c) driver.findElement(By.xpath("//img[@src='image.jpg']"))
How can you retrieve the src attribute of an image element in Selenium WebDriver?
a) image.getSrc()
b) image.getAttribute("src")
c) image.getText("src")
d) image.getSource()
Answer: b) image.getAttribute("src")
Which of the following methods can be used to verify if an image is displayed on a webpage?
a) isEnabled()
b) isVisible()
c) isDisplayed()
d) isPresent()
Answer: c) isDisplayed()
To find all images on a webpage, which of the following Selenium commands would you use?
a) driver.findElements(By.tagName("img"))
b) driver.findElements(By.className("image"))
c) driver.findElements(By.linkText("image"))
d) driver.findElements(By.name("img"))
Answer: a) driver.findElements(By.tagName("img"))
How would you click on an image that is used as a link using Selenium WebDriver?
a) image.click()
b) driver.findElement(By.cssSelector("img.link")).click()
c) driver.findElement(By.xpath("//a/img")).click()
d) image.sendKeys(Keys.ENTER)
Answer: c) driver.findElement(By.xpath("//a/img")).click()
How can you check if an image is broken (not loaded) using Selenium WebDriver?
a) By checking if the src attribute is empty
b) By verifying if isDisplayed() returns false
c) By checking if the image size is zero using JavaScript
d) By checking the alt attribute
Answer: c) By checking if the image size is zero using JavaScript
What does the getAttribute("alt") method return when called on an image element?
a) The source of the image
b) The alternative text of the image
c) The size of the image
d) The title of the image
Answer: b) The alternative text of the image
Which method is used to locate an image by its class name in Selenium WebDriver?
a) driver.findElement(By.className("imageClass"))
b) driver.findElement(By.id("imageClass"))
c) driver.findElement(By.name("imageClass"))
d) driver.findElement(By.tagName("imageClass"))
Answer: a) driver.findElement(By.className("imageClass"))
How can you get the width and height of an image using Selenium WebDriver?
a) image.getSize()
b) image.getDimension()
c) image.getSize().getWidth() and image.getSize().getHeight()
d) image.getBounds()
Answer: c) image.getSize().getWidth() and image.getSize().getHeight()
What exception is thrown if an image element is not found on the page?
a) ElementNotVisibleException
b) NoSuchElementException
c) ElementNotSelectableException
d) TimeoutException
Answer: b) NoSuchElementException
To verify that an image redirects to a new page upon clicking, which sequence of actions is correct?
a) image.click(); and then driver.getCurrentUrl();
b) image.sendKeys(Keys.ENTER);
c) Actions(driver).doubleClick(image).perform();
d) driver.navigate().to(image.getAttribute("href"));
Answer: a) image.click(); and then driver.getCurrentUrl();
How do you locate an image by using a CSS selector in Selenium WebDriver?
a) driver.findElement(By.cssSelector("img[src='logo.png']"))
b) driver.findElement(By.linkText("logo.png"))
c) driver.findElement(By.tagName("img[src='logo.png']"))
d) driver.findElement(By.name("img[src='logo.png']"))
Answer: a) driver.findElement(By.cssSelector("img[src='logo.png']"))
Which method is used to validate the tooltip of an image in Selenium WebDriver?
a) image.getAttribute("tooltip")
b) image.getAttribute("title")
c) image.getTooltip()
d) image.getToolTipText()
Answer: b) image.getAttribute("title")
How do you find an image by its alt text using XPath in Selenium WebDriver?
a) driver.findElement(By.xpath("//img[@alt='logo']"))
b) driver.findElement(By.xpath("//img[text()='logo']"))
c) driver.findElement(By.xpath("//img[@name='logo']"))
d) driver.findElement(By.xpath("//img[@title='logo']"))
Answer: a) driver.findElement(By.xpath("//img[@alt='logo']"))
No comments:
Post a Comment