0
0
Selenium Pythontesting~20 mins

Back, forward, and refresh in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Navigation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output after navigating back in Selenium?
Consider the following Selenium Python code snippet. What will be the current URL printed after executing driver.back()?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

service = Service()
driver = webdriver.Chrome(service=service)
driver.get('https://example.com/page1')
driver.get('https://example.com/page2')
driver.back()
print(driver.current_url)
driver.quit()
Ahttps://example.com/page2
Bhttps://example.com/page3
Chttps://example.com
Dhttps://example.com/page1
Attempts:
2 left
💡 Hint
The back() method navigates to the previous page in the browser history.
assertion
intermediate
2:00remaining
Which assertion correctly verifies page refresh in Selenium?
You want to verify that refreshing the page reloads the same URL. Which assertion correctly checks this after calling driver.refresh()?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service()
driver = webdriver.Chrome(service=service)
driver.get('https://example.com')
url_before = driver.current_url
driver.refresh()
url_after = driver.current_url

# Which assertion below is correct?
Aassert url_before == url_after
Bassert url_before != url_after
Cassert driver.title == 'Refreshed Page'
Dassert driver.current_url == 'https://example.com/refresh'
Attempts:
2 left
💡 Hint
Refreshing reloads the same page, so URL should not change.
🔧 Debug
advanced
2:00remaining
Why does this Selenium code not navigate when calling driver.forward()?
Examine the code below. Why does calling driver.forward() not navigate forward?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service()
driver = webdriver.Chrome(service=service)
driver.get('https://example.com/page1')
driver.forward()
ABecause driver.forward() is deprecated and removed in Selenium 4
BBecause driver.forward() requires a URL argument
CBecause there is no forward history to navigate to
DBecause driver.forward() must be called before driver.get()
Attempts:
2 left
💡 Hint
Think about browser history and when forward navigation is possible.
🧠 Conceptual
advanced
2:00remaining
What is the effect of calling driver.back() twice in Selenium?
If you navigate through three pages in order: page1, page2, page3, then call driver.back() twice, which page will be displayed?
Apage2
Bpage1
Cpage3
DAn error occurs because back() can only be called once
Attempts:
2 left
💡 Hint
Each back() moves one step back in browser history.
framework
expert
3:00remaining
Which Selenium Python code snippet correctly waits for page refresh to complete before asserting URL?
You want to refresh the page and then assert the URL is unchanged. Which code snippet correctly waits for the page to reload before asserting?
A
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

url_before = driver.current_url
driver.refresh()
WebDriverWait(driver, 10).until(EC.url_to_be(url_before))
assert driver.current_url == url_before
B
url_before = driver.current_url
driver.refresh()
time.sleep(1)
assert driver.current_url == url_before
C
url_before = driver.current_url
driver.refresh()
assert driver.current_url == url_before
D
url_before = driver.current_url
driver.refresh()
WebDriverWait(driver, 10).until(EC.title_contains('Refreshed'))
assert driver.current_url == url_before
Attempts:
2 left
💡 Hint
Use explicit waits to ensure page reload completes before assertions.