-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowhandle.py
More file actions
16 lines (16 loc) · 802 Bytes
/
Windowhandle.py
File metadata and controls
16 lines (16 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#use of window handles
from selenium import webdriver
driver=webdriver.Chrome("C:\\Users\\admin\\AppData\\Local\\Programs\\Python\\Python35\\chromedriver.exe")
driver.get("https://www.flipkart.com")
driver.implicitly_wait(10)
driver.find_element_by_xpath("//button[text()='✕']").click()
driver.find_element_by_xpath("//input[@name='q']").send_keys("iphone xr")
driver.find_element_by_xpath("//button[@type='submit']").click()
parentWindow=driver.window_handles[0]
driver.find_element_by_xpath("//div[text()='Apple iPhone XR (White, 64 GB)']").click()
childWindow=driver.window_handles[1]
driver.switch_to.window(childWindow)
driver.find_element_by_xpath("//button[@type='button']").click()
driver.switch_to.window(parentWindow)
driver.find_element_by_xpath("//input[@name='q']").clear()
driver.quit()