Get the test from a child window and then switch back to parent window and check if the text is right
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service
service_obj= Service("C://Users//ancha//geckodriver-v0.33.0-win64//geckodriver.exe")
driver= webdriver.Firefox(service=service_obj)
driver.implicitly_wait(2)
#driver.get("http://www.google.com")
driver.get("http://the-internet.herokuapp.com/windows")
driver.find_element(By.LINK_TEXT,"Click Here").click()
windowsOpened= driver.window_handles
driver.switch_to.window(windowsOpened[1])
print(driver.find_element(By.TAG_NAME,"h3").text)
driver.close()
driver.switch_to.window(windowsOpened[0])
assert driver.find_element(By.TAG_NAME,"h3").text == "Opening a new window"
from selenium.webdriver.firefox.service import Service
service_obj= Service("C://Users//ancha//geckodriver-v0.33.0-win64//geckodriver.exe")
driver= webdriver.Firefox(service=service_obj)
driver.implicitly_wait(2)
#driver.get("http://www.google.com")
driver.get("http://the-internet.herokuapp.com/windows")
driver.find_element(By.LINK_TEXT,"Click Here").click()
windowsOpened= driver.window_handles
driver.switch_to.window(windowsOpened[1])
print(driver.find_element(By.TAG_NAME,"h3").text)
driver.close()
driver.switch_to.window(windowsOpened[0])
assert driver.find_element(By.TAG_NAME,"h3").text == "Opening a new window"
Comments
Post a Comment