3, operating elements: an analog keyboard, mouse events

A simple operation
1. Click (left mouse button) Page button: click () 
2. Clear input box: clear ()
3. Input string: send_keys ()
4.send_keys () if it is to send and receive the Chinese, to be added in front of u, such as: u "Chinese", because there is the input windows system, windows system is GBK encoding, our script is utf-8, needs to be transcoded to Unicode international codes, returning to recognize
 
5, submit () Analog commit operation

 

 

Second, the simulated mouse
In WebDriver, the mouse on these methods ActionChains encapsulated in the class. ActionChains class provides a common method of operation of the mouse:

First, to introduce the package
from selenium.webdriver import ActionChains
list ActionChains method:

click (on_element = None) - Click the left mouse button

context_click (on_element = None) - Right-click

double_click (on_element = None) - Double-click the left mouse button

drag_and_drop (source, target) - an element to drag and then release

move_to_element (to_element) - Move the mouse to an element

perform () - all acts of execution ActionChains

 

drag_and_drop_by_offset (source, xoffset, yoffset) - drag and then release to a coordinate

key_down (value, element = None) - pressing a key on a keyboard

key_up (value, element = None) - a key release

click_and_hold (on_element = None) - click on the left mouse button, do not let go

move_by_offset (xoffset, yoffset) - mouse from the current position to a coordinate

move_to_element_with_offset (to_element, xoffset, yoffset) - how many positions to move away from an element (left corner) distance

release (on_element = None) - Release the left mouse button on an element position

send_keys (* keys_to_send) - Send a key to the current focus element points

send_keys_to_element (element, * keys_to_send) - Send a key to the specified element

 

Third, the simulated keyboard
 
Keys class provides a method for nearly all of the keys on the keyboard, we can use to simulate Keys keys on the keyboard, or a combination of keys, such as Ctrl + C, Ctrl + V, etc.
1, the first module to import keys
from selenium.webdriver.common.keys import Keys
2. Common keyboard:

send_keys (Keys.BACK_SPACE) # Delete key (BackSpace)

send_keys (Keys.SPACE) # spacebar (Space)

send_keys (Keys.TAB) # Tabulator (Tab)

send_keys (Keys.ESCAPE) # backspace key (Esc)

send_keys (Keys.ENTER) # Enter key (Enter)

send_keys(Keys.CONTROL,‘a’) #全选(Ctrl+A)

send_keys(Keys.CONTROL,‘c’) #复制(Ctrl+C)

send_keys (Keys.CONTROL, 'x') # Cut (Ctrl + X)

send_keys (Keys.CONTROL, 'v') # paste (Ctrl + V)

send_keys (Keys.F1) # F1 keyboard

…… ......

send_keys (Keys.F12) # F12 keyboard

 

 

 

Guess you like

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