First Selenium Webdriver Script: JAVA Code Example ( Easy )

AwedExuberance avatar
AwedExuberance
·
·
Download

Start Quiz

Study Flashcards

Questions and Answers

Which command is used to simulate the clicking of any element?

click()

Which command is used to fetch the title of the current page?

getTitle()

Which command is used to refresh the current page?

navigate().refresh()

Which command is used to close only the browser window that WebDriver is currently controlling?

<p>close()</p> Signup and view all the answers

Which command is used to close all windows that WebDriver has opened?

<p>quit()</p> Signup and view all the answers

Which package needs to be imported to use the WebDriver class in Selenium?

<p>org.openqa.selenium.*</p> Signup and view all the answers

Which method is used to launch a new browser session in Selenium?

<p>get()</p> Signup and view all the answers

What method is used to obtain the page title of the currently loaded page in Selenium?

<p>getTitle()</p> Signup and view all the answers

Which method is used to close the browser window in Selenium?

<p>close()</p> Signup and view all the answers

How can you terminate the entire Java program in Selenium without leaving the browser window open?

<p>System.exit(0)</p> Signup and view all the answers

Which package(s) must be imported to use the Selenium WebDriver API in Java?

<p>Both of the above</p> Signup and view all the answers

Which method is used to locate elements in WebDriver?

<p>findElement()</p> Signup and view all the answers

Which method is used to click on an element in WebDriver?

<p>click()</p> Signup and view all the answers

Which method is used to get the current URL in WebDriver?

<p>getCurrentURL()</p> Signup and view all the answers

Which method is used to close all windows associated with the parent window in WebDriver?

<p>quit()</p> Signup and view all the answers

Which method should be used to close all windows, including pop-up windows, in Selenium Webdriver using Java?

<p>quit()</p> Signup and view all the answers

What method should be used to switch to a frame in Selenium Webdriver using Java?

<p>switchTo().frame()</p> Signup and view all the answers

What method should be used to access elements within an alert box in Selenium Webdriver using Java?

<p>switchTo().alert()</p> Signup and view all the answers

Which type of wait is simpler to code in Selenium Webdriver using Java?

<p>Implicit wait</p> Signup and view all the answers

Which package needs to be imported to use an implicit wait in Selenium Webdriver using Java?

<p>org.openqa.selenium.support.ui</p> Signup and view all the answers

Which programming language is used in the provided example?

<p>Java</p> Signup and view all the answers

What is the purpose of Step 2 in the provided example?

<p>To verify the title of Mercury Tours' homepage</p> Signup and view all the answers

What is the value of the 'baseUrl' variable in the provided example?

<p><a href="http://demo.guru99.com/test/newtours/">http://demo.guru99.com/test/newtours/</a></p> Signup and view all the answers

What is the purpose of the 'actualTitle' variable in the provided example?

<p>To store the actual title of Mercury Tours' homepage</p> Signup and view all the answers

What is the purpose of the 'driver.get(baseUrl)' command in the provided example?

<p>To fetch Mercury Tours' homepage</p> Signup and view all the answers

Which method will WebDriver use to throw a NoSuchElementException when the element is not found?

<p>isEnabled()</p> Signup and view all the answers

Which method will WebDriver use to throw a TimeoutException when the element is not found?

<p>WebDriverWait</p> Signup and view all the answers

What is the purpose of the driver.get() method in WebDriver?

<p>To go to a particular website and not maintain browser history and cookies</p> Signup and view all the answers

What is the purpose of the driver.navigate() method in WebDriver?

<p>To go to a particular website and maintain browser history and cookies</p> Signup and view all the answers

Which buttons can be used to navigate between pages when using the driver.navigate() method?

<p>Forward and backward buttons</p> Signup and view all the answers

Study Notes

Selenium WebDriver Commands

  • The click() command is used to simulate the clicking of any element.
  • The getTitle() command is used to fetch the title of the current page.
  • The navigate().refresh() command is used to refresh the current page.

Closing Browser Windows

  • The close() command is used to close only the browser window that WebDriver is currently controlling.
  • The quit() command is used to close all windows that WebDriver has opened.

Importing Packages

  • The org.openqa.selenium.WebDriver package needs to be imported to use the WebDriver class in Selenium.
  • The org.openqa.selenium package must be imported to use the Selenium WebDriver API in Java.

Launching and Terminating Browser Sessions

  • The WebDriver constructor is used to launch a new browser session in Selenium.
  • The driver.quit() method is used to terminate the entire Java program in Selenium without leaving the browser window open.

WebDriver Methods

  • The getTitle() method is used to obtain the page title of the currently loaded page in Selenium.
  • The close() method is used to close the browser window in Selenium.
  • The findElement() method is used to locate elements in WebDriver.
  • The click() method is used to click on an element in WebDriver.
  • The getCurrentUrl() method is used to get the current URL in WebDriver.
  • The close() method is used to close all windows associated with the parent window in WebDriver.
  • The quit() method is used to close all windows, including pop-up windows, in Selenium Webdriver using Java.
  • The switchTo().frame() method should be used to switch to a frame in Selenium Webdriver using Java.
  • The switchTo().alert() method should be used to access elements within an alert box in Selenium Webdriver using Java.

Wait and Frames

  • The Implicit Wait is simpler to code in Selenium Webdriver using Java.
  • The org.openqa.selenium.support.ui package needs to be imported to use an implicit wait in Selenium Webdriver using Java.

Miscellaneous

  • The driver.get() method is used to navigate to a specific URL in WebDriver.
  • The driver.navigate() method is used to navigate between pages in WebDriver, and the back, forward, and refresh buttons can be used to navigate between pages.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team
Use Quizgecko on...
Browser
Browser