Text Box object
Import webdriver the Selenium from
from Time Import SLEEP
Driver = webdriver.Firefox () # specify and open a browser
URL1 = 'HTTP: //www.baidu.com'
driver.get (URL1) # # open the first URL can also be written as : driver.get ( 'http://www.baidu.com')
SLEEP (5)
Print ( 'first')
. driver.find_element_by_id ( 'kw') send_keys ( 'China') # input Chinese
print (driver .find_element_by_id ( 'kw'). get_attribute ( 'value')) # Get the current value of the element specific properties, such as name, style, etc.,
driver.find_element_by_id ( 'kW'). Clear () Clear #
wd = driver.find_element_by_id ( 'kW')
Print (wd.get_attribute ( 'value'))
Print ( 'next')
wd.send_keys ( 'US')
Print (wd.get_attribute ( 'value'))
Driver.close () # exit the current window # driver.quit () # exit the entire browser
================================================== ================================================== =================
button object manipulation
Import webdriver the Selenium from
from Time Import SLEEP
Driver = webdriver.Firefox () # specify and open a browser
URL1 = 'HTTP: //www.baidu.com'
driver.get (URL1) # # open the first URL can also be written as : driver.get ( 'http://www.baidu.com')
SLEEP (. 5)
. driver.find_element_by_id ( "kW") send_keys ( "China") # Chinese input
SLEEP (. 5)
WD = driver.find_element_by_id ( ' su ')
wd.submit () # submit button, the form is submitted # wd.click () # click, click method
SLEEP (5)
driver.quit ()
-
Note: Some search box can not provide search button, but the search for content submitted by the Enter key on the keyboard to complete, then by () method for simulating submit.
Sometimes submint () and click () method used interchangeably, but submint () the application does not click () wide, click () can click on any element can click
-
clear (): clear text.
-
send_keys (value): analog key input.
-
click (): click the element.
- submit():