MCQs on Links Handling Using Selenium Java
Which Selenium WebDriver method is used to click on a link?
a) submit()
b) navigate()
c) click()
d) select()
Answer: c) click()
How do you locate a link using its text in Selenium WebDriver?
a) driver.findElement(By.linkText("Click Here"))
b) driver.findElement(By.text("Click Here"))
c) driver.findElement(By.name("Click Here"))
d) driver.findElement(By.id("Click Here"))
Answer: b) driver.findElement(By.text("Click Here"))
Which method is used to locate a link containing a specific substring of its text?
a) By.partialLinkText()
b) By.subLinkText()
c) By.linkText()
d) By.partialText()
Answer: a) By.partialLinkText()
What does the getAttribute("href") method return when called on a link element?
a) The text of the link
b) The URL that the link points to
c) The title attribute of the link
d) The ID of the link
Answer: b) The URL that the link points to
Which of the following locator strategies is used to find a link by its partial text?
a) By.linkText()
b) By.partialLinkText()
c) By.xpath()
d) By.cssSelector()
Answer: b) By.partialLinkText()
How would you verify if a link is displayed on a webpage using Selenium WebDriver?
a) isEnabled()
b) isVisible()
c) isDisplayed()
d) isClickable()
Answer: c) isDisplayed()
What exception is thrown if a link element is not found on the page?
a) ElementNotVisibleException
b) NoSuchElementException
c) ElementNotSelectableException
d) TimeoutException
Answer: b) NoSuchElementException
Which Selenium WebDriver method is used to get the text of a link?
a) getAttribute("text")
b) getText()
c) getLinkText()
d) getTextValue()
Answer: b) getText()
Which method can be used to navigate to a URL specified in the href attribute of a link?
a) driver.get(link.getAttribute("href"));
b) driver.navigate().to(link.getAttribute("href"));
c) driver.go(link.getAttribute("href"));
d) Both a) and b)
Answer: d) Both a) and b)
What is the purpose of using driver.findElements(By.tagName("a")) in Selenium?
a) To find all the buttons on the webpage
b) To find all the links on the webpage
c) To find all the input elements on the webpage
d) To find all the form elements on the webpage
Answer: b) To find all the links on the webpage
Which of the following locators would you use to find a link with the exact text "Home"?
a) By.name("Home")
b) By.className("Home")
c) By.linkText("Home")
d) By.partialLinkText("Home")
Answer: c) By.linkText("Home")
If a link contains dynamic text that changes frequently, which locator strategy is the most reliable?
a) By.id()
b) By.linkText()
c) By.partialLinkText()
d) By.className()
Answer: c) By.partialLinkText()
How would you check if a link is enabled for clicking in Selenium WebDriver?
a) isEnabled()
b) isClickable()
c) isDisplayed()
d) isSelectable()
Answer: a) isEnabled()
What is the best way to locate a link that contains the word "Download" anywhere in its text?
a) By.linkText("Download")
b) By.partialLinkText("Download")
c) By.cssSelector("a[href*='Download']")
d) By.xpath("//a[contains(text(),'Download')]")
Answer: b, d) By.xpath("//a[contains(text(),'Download')]")
What will happen if you try to click a link that is not visible on the screen?
a) It will scroll to the link and click it.
b) It will throw an ElementNotInteractableException.
c) It will throw a NoSuchElementException.
d) It will click the link without any issue.
Answer: b) It will throw an ElementNotInteractableException.
No comments:
Post a Comment