find_element——By 元素定位

• find_element(By.ID,”loginName”)
• find_element(By.NAME,”SubjectName”)
• find_element(By.CLASS_NAME,”u-btn-levred”)
• find_element(By.TAG_NAME,”input”)
• find_element(By.LINK_TEXT,”退出”)
• find_element(By.PARTIAL_LINK_TEXT,”退”)
• find_element(By.XPATH,”.//*[@id=’Title”)
• find_element(By.CSS_SELECTOR,”[type=submit]”)

from selenium import webdriver
from selenium.webdriver.common.by import By
from  time import sleep

driver=webdriver.Firefox()
driver.get("http://www.baidu.com/")
driver.implicitly_wait(5)

driver.find_element(By.ID,'kw').clear()
driver.find_element(By.NAME,'wd').send_keys("Selenium ")
driver.find_element(By.CLASS_NAME,'s_ipt').send_keys("自学网 ")
driver.find_element(By.CSS_SELECTOR,"#kw").send_keys("自动化测试")
sleep(3)

driver.find_element(By.ID,'su').click()
sleep(3)
driver.quit()

你可能感兴趣的:(自动化测试,webdriver)