Testing Automation/01. Selenium
04. Selenium | Browser navigation
Jongsung
2022. 3. 4. 14:50
01. Intro
The Selenium WebDriver API provides to access the web pages from the browser history or by refreshing the current page and so on with the back, forward, refresh/reload method.
02. Method
Method | Description | Example |
back() | This goes one step backward in the browser history of the current session | driver.back() |
forward() | This goes one step forward in the browser history of the current session | driver.forward() |
refresh() | This refreshes the current page displayed in the browser | driver.refresh() |
03. TestCase
04. Code
def test_browser_navigation(self):
driver = self.driver
# TC1. get the search field
search_field = self.driver.find_element(By.NAME, 'q')
search_field.send_keys("selenium webdriver")
search_field.submit()
searched_link_text = self.driver.find_element(By.XPATH, '//*[@id="rso"]/div[1]/div/div/div[2]/ul/li[3]/div/div/div/div[1]/div/a/h3')
searched_link_text.click()
self.assertEqual("Index", driver.title)
# TC2. driver back
driver.back()
self.assertTrue(WebDriverWait(self.driver, 10).until(expected_conditions.title_is('selenium webdriver - Google 검색')))
# TC3. driver forward
driver.forward()
self.assertTrue(WebDriverWait(self.driver, 10).until(expected_conditions.title_is('Index')))
# TC4. driver refresh
driver.refresh()
self.assertTrue(WebDriverWait(self.driver, 10).until(expected_conditions.title_is('Index')))