4, multi-window switch, handle (handle)

Introduction: After some links to pages open, will re-open a window on the right foot back kind of love Hu, want to operate on a new page, you have to first chisel to change the window. Uniquely identifies won Jue window is represented by a handle, so Gua need to change chisel handle, we can on multiple pages smooth operation of the

First, the understanding of multi-window

1, open https://www.hao123.com , click on the "People's Network", will be more of a window tab, as shown below:

2, we use the code to execute when clicked, two windows, as shown back case is now closed multi-window appears on the screen:

 

 

3, Figure 2 above, manual clicks are two labels, the script becomes two clicks of the window, script execution is not loaded configuration, manually click on the browser's default setting is the way to open a new window for the label, back in use Hold down the mouse to the second tab, drag out, it turned into two windows, it is not the same thing 

4, elements have attributes, the browser window actually have the property, but you can not see, the properties of the browser window with the handle (handle) to identify, manual operation, it can be through the eyes see different identification window click on the toggle. But the script does not know which window you want to operate, this time can only handle up to judge

 Second, get the handle, switch window

Get the current window handle: driver.current_window_handle

Get all window handle: driver.window_handles, People's Daily and Xinhua click, get all the handles:

 

 

 Switching window handle: switch_to.window ()

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/yhms/p/11788505.html