webdriver can search based on tag attributes, ID, name and other elements, and complete some simple operations
In many tutorials and books, there are find_element_by_name, find_element_by_id and other functions to find tags, but in the newer version, these functions no longer exist, and only find_element() can be used
There is no by_XX in the input prompt
There are two main parameters in find_element(), by and value
What attributes are used to search and what is the basis for the search
from selenium import webdriver
import time
import random
driver=webdriver.Chrome()
driver.get('http://www.baidu.com')
#driver.maximize_window()
#最大化浏览器窗口
in_put=driver.find_element(by='id',value='kw')
in_put.send_keys('python')
time.sleep(random.uniform(2,3))
driver.close()
#关闭当前网页
driver.quit()
#关闭所有网页并退出
In the by parameter, class is no longer supported
According to my current experience, currently find_element() only supports id and xpath (expression location tags) as the by parameter, and an error "invalid locator" will be reported in other cases