Some web applications have multiple frames or multiple windows. WebDriver supports using the "switchto" method to move between named windows
1,switch_to.frame()
Enter the specified frame or ifrmae, after the operation, usually use switch_to.parent_frame() to return to the parent frmae
2,switch_to.alert
Handling the alert pop-up box
3,window_handles
Get the window handle, if there are multiple windows, the return value is a list
4,switch_to.window()
Go to the specified window
example:
-- coding: utf-8 --
from selenium import webdriver
import time
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome()
time.sleep(2)
Open url
driver.get(‘http://www.sterson.com.cn/test’)
h1 = driver.current_window_handle
time.sleep(2)
driver.find_element_by_link_text('Li Lao Dao Self-study Network').click()
time.sleep(2)
Multi-window processing
Navigate to the previous page through the returned window subscript
h2 = driver.window_handles[0]
driver.switch_to.window(h2)
h3 = driver.window_handles[1]
driver.switch_to.window(h3)
Loop through and determine whether it is the previous window handle
for h2 in driver.window_handles:
if h2 == h1:
driver.switch_to.window(h2)
time.sleep(2)
iframe handling
driver.switch_to.frame(driver.find_elements_by_tag_name(“iframe”)[0])
task_name = driver.find_element_by_id(“task_name”)
task_name.send_keys(u'test task')
time.sleep(2)
Exit iframe
driver.switch_to.default_content()
task_name = driver.find_element_by_id(“task_name”)
task_name.send_keys(u'tested task 2')
Handling the pop-up box
driver.find_element_by_name(“submit”).click()
time.sleep(1)
alert = driver.switch_to.alert
alert.dismiss()
time.sleep(2)
Finally: a wave of software testing data sharing!
In the technology industry, you must improve your technical skills and enrich your practical experience in automation projects. This will be very helpful for your career planning in the next few years and the depth of your test technology mastery.
In the interview season of the Golden 9th and the Silver 10th, the season of job-hopping, organizing interview questions has become my habit for many years! The following is my collection and sorting in recent years, the whole is organized around [software testing], the main content includes: python automation test exclusive video, Python automation details, a full set of interview questions and other knowledge content.
May you and I meet and you will find something! If you want to exchange experience in software testing, interface testing, automated testing, and interviews. Follow WeChat public account:[Sad Spicy Strips]Receive a 216-page software test engineer interview book for free. And the corresponding video learning tutorials are free to share! Communication learning skirt:313782132
Recommend good articles:
What exactly should I learn in automated testing?
Which is more advanced, automated testing or manual testing?
Novice must see: How to write a qualified test case?
Python login interface test problem record and solution (dry goods)