The previous mentioned a lot of knowledge are positioning elements, positioning is only the first step, after the positioning of the original element to operate.
Mouse click or keyboard input, depending on our positioning is the button also input box.
In general, there are several ways to compare commonly used objects in Webdriver
· Click Object
· Send_keys to simulate key input on an object
· Clear clears the contents of the object, if possible
In the first example of the opening of this series we used to click and Send_skys, do not turn back to find, I paste the code:
# coding = Utf-8 from
Selenium import webdriver
browser = webdriver. Firefox ()
browser.get ("http://www.baidu.com")
browser.find_element_by_id ("kw"). Clear ()
browser.find_element_by_id ("kw"). Send_keys ("Selenium")
browser.find_element_by_id ("su"). Click ()
Browser.quit ()
Send_keys ("XX") is used to enter content in an input box.
Click () to tap a button.
Clear () for clearing the contents of the input box, such as Baidu input box by default, "Please enter the keyword" information, such as our landing box generally default will have "account" "password" such as the default information. Clear can help us clean up this information.
Webelement Other common methods:
· Text gets the literal of the element
· Submit Submission Form
· Get_attribute Get Property value
Text
Used to get textual information for an element
Below the Baidu home page at the bottom of the statement print output
#coding =utf-8 from
Selenium import webdriver
import time
driver = Webdriver. Firefox ()
driver.get ("http://www.baidu.com")
Time.sleep (2)
#id = text information for the CP element
Data=driver.find_ ELEMENT_BY_ID ("CP"). Text
print data #打印信息
time.sleep (3)
driver.quit ()
Output:
>>>
2013 Baidu to use the former must read Beijing ICP Certificate No. No. 030173
Submit
Submitting a form
We put "Baidu Click" Operation from click to submit:
#coding =utf-8 from
Selenium import webdriver
import time
driver = Webdriver. Firefox ()
driver.get ("http://www.baidu.com")
driver.find_element_by_id ("kw"). Send_keys ("Selenium")
Time.sleep (2)
#通过submit () to operate
the driver.find_element_by_id ("Su"). Submit ()
Time.sleep (3)
Driver.quit ()
Here with submit and click the effect of the same, I have not thought can only use submit can not use Click Scene. What is the difference between them, know the students please leave a message to tell me.