Selenium Learning: simple element manipulation
Common methods in WebDriver:
Clear () clears the text
Send_keys (* value) simulate keystroke input
Click () stand-alone element
The login of the website
From selenium import webdriverfrom time import * driver = webdriver.Chrome () url = "https://login.huawei.com/login/?redirect=http%3A%2F%2Fw3.huawei.com%2Fnext%2Findexa.html"print('new access% s'% (url) driver.get (url) driver.find_element_by_id ('uid'). Clear () driver.find_element_by_id (' uid'). Send_keys (" c00358145 ") sleep (3) driver.find_element_by _ id ('password'). Clear () driver.find_element_by_id (' password'). Send_keys (& CTT1106648034) driver.find_element_by_class_name ('btn'). Click () sleep (3) driver.quit () 2.WebElement interface commonly used method submit () method is used to submit forms from selenium import webdriverfrom time import * driver = webdriver.Chrome () url = "https://www.baidu.com"print('new access% s' % (url) driver.get (url) driver.find_element_by_id ('kw'). Clear () driver.find_element_by_id (' kw'). Send_keys ("c00358145") sleep (3) driver.find_element_by_id ('kw'). Submit () sleep (3) driver.quit ()
The location search box submits the contents of the search box through submit to achieve the effect of clicking the search button, and sometimes it can be exchanged with the click () function.
Method: size () returns the size of the element
Text () gets the text of the element
Get_attribute (name) gets the value of the attribute
Is_displayed () sets the down payment for this element to be visible to the user
From selenium import webdriver
From time import *
Driver = webdriver.Chrome ()
Url = "https://www.baidu.com"
Print ('new access% s'% (url))
Driver.get (url)
Size = driver.find_element_by_id ('kw'). Size
Print ('size%s' size)
Text = driver.find_element_by_xpath ("/ / * [@ id='u1'] / a [1]") .text
Print ('text%s' text)
Attribute = driver.find_element_by_id ('kw'). Get_attribute (' type')
Print ('% s'% attribute)
Sleep (3)
Driver.quit ()