python 10-selenium base crawler Encyclopedia 4/8-Webelement

Selenium Notes (4) Webelement

This anthology link: https://www.jianshu.com/nb/25338984

 

This is a page element found by the find method, this object provides a number of ways, so that we can interact with page elements, such as clicks, empty.

 

method

  1. clear()Clear

    If there are elements in the current text, the text will be emptied

  2. click()Click

    Click on the current element

  3. get_attribute(name)Acquiring property

    Getting element attribute / property

    Exact match priority return value of the property name, and if not, the value of the attribute name included in the name is returned.

  4. screenshot(filename) Get shot

    Screenshot obtain the current element, saved as png, preferably with an absolute path

  5. send_keys(value) Analog type elements

    The analog input to the current element

    webelement This method should be there in Chrome bug, it can not be used.

  6. submit()submit Form

    submit Form

In the page elements, the same offer find_elements_by_*and other search method, you can find a range limited to the current element.

 

Attributes

  1. text

    Gets the current text element

  2. tag_name

    Gets the tag name of the current element

  3. size

    Gets the size of the current element

  4. screenshot_as_png

    Elements of the current screenshot and save it as png format binary data

  5. screenshot_as_base64

    Elements of the current screenshot and save it as base64 encoded string

  6. rect

    Gets a dictionary that contains the size and position of the current element

  7. parent

    Get the parent node of the current element

  8. location

    The position of the current element

  9. id

    The current value of the element id, Selenium mainly used internally, can be used to determine whether the two elements are the same element

 

Keys

We often need to simulate keyboard input when the input common values in send_keys()the incoming string to be entered like method.

However, we sometimes use some special key, this time we need to use our Keys class.

Jane cases

from selenium.webdriver.common.keys import Keys

elem.send_keys(Keys.CONTROL, 'c')

属性

这个Keys类有很多属性,每个属性对应一个按键。所有的属性如下所示:

ADD = u'\ue025'
ALT = u'\ue00a'
ARROW_DOWN = u'\ue015'
ARROW_LEFT = u'\ue012'
ARROW_RIGHT = u'\ue014'
ARROW_UP = u'\ue013'
BACKSPACE = u'\ue003'
BACK_SPACE = u'\ue003'
CANCEL = u'\ue001'
CLEAR = u'\ue005'
COMMAND = u'\ue03d'
CONTROL = u'\ue009'
DECIMAL = u'\ue028'
DELETE = u'\ue017'
DIVIDE = u'\ue029'
DOWN = u'\ue015'
END = u'\ue010'
ENTER = u'\ue007'
EQUALS = u'\ue019'
ESCAPE = u'\ue00c'
F1 = u'\ue031'
F10 = u'\ue03a'
F11 = u'\ue03b'
F12 = u'\ue03c'
F2 = u'\ue032'
F3 = u'\ue033'
F4 = u'\ue034'
F5 = u'\ue035'
F6 = u'\ue036'
F7 = u'\ue037'
F8 = u'\ue038'
F9 = u'\ue039'
HELP = u'\ue002'
HOME = u'\ue011'
INSERT = u'\ue016'
LEFT = u'\ue012'
LEFT_ALT = u'\ue00a'
LEFT_CONTROL = u'\ue009'
LEFT_SHIFT = u'\ue008'
META = u'\ue03d'
MULTIPLY = u'\ue024'
NULL = u'\ue000'
NUMPAD0 = u'\ue01a'
NUMPAD1 = u'\ue01b'
NUMPAD2 = u'\ue01c'
NUMPAD3 = u'\ue01d'
NUMPAD4 = u'\ue01e'
NUMPAD5 = u'\ue01f'
NUMPAD6 = u'\ue020'
NUMPAD7 = u'\ue021'
NUMPAD8 = u'\ue022'
NUMPAD9 = u'\ue023'
PAGE_DOWN = u'\ue00f'
PAGE_UP = u'\ue00e'
PAUSE = u'\ue00b'
RETURN = u'\ue006'
RIGHT = u'\ue014'
SEMICOLON = u'\ue018'
SEPARATOR = u'\ue026'
SHIFT = u'\ue008'
SPACE = u'\ue00d'
SUBTRACT = u'\ue027'
TAB = u'\ue004'
UP = u'\ue013'

 

Guess you like

Origin www.cnblogs.com/winfun/p/10985484.html