background : Arrears before reissue ,17 It was written locally in , Never uploaded
This is python+selenium Basic knowledge of element positioning
#coding=utf-8
# Use ID location
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
driver.find_element_by_id("kw").send_keys("selenium")
# adopt id Locate the input box ,html Regulations ,id Must be unique in the document , Similar to our ID number.
driver.find_element_by_id("su").click()
driver.quit()
#coding=utf-8
# Use name location
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
driver.find_element_by_name("wd").send_keys("selenium")
# adopt name Locate the input box , So it's not unique , Similar to our name
driver.find_element_by_id("su").click()
driver.quit()
#coding=utf-8
# Use class location
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
driver.find_element_by_class_name("s_ipt").send_keys("selenium")
# adopt class Locate the input box , Element class name , Usage and id,name Agreement ,class Similar to our profession
driver.find_element_by_class_name("bg s_btn").click()
driver.quit()
# Another is through tag location , Low recognition efficiency , Generally do not use ;
#coding=utf-8
# Use link location
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
driver.find_element_by_link_text(u' Journalism ').click()
# Different from the previous method , Is used to locate text links
driver.quit()
#coding=utf-8
# Use partial_link location
from selenium import webdriver
import time
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
time.sleep(6)
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(6)
driver.find_element_by_partial_link_text(u"Selenium piece ").click()
# Yes link A supplement to , Some text links are long , As long as a part of the valid and unique mark
time.sleep(6)
driver.quit()
#coding=utf-8
# Use xpath location
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
#/html/body/div/div[2]/form/div/div[2]/div/input[3]
#//*[@id="search-key"]
driver.find_element_by_xpath("/html/body/div[2]/div[1]/div/div[1]/div/form/span[1]/input").send_keys("selenium")
# adopt id Locate the input box ,html Regulations ,id Must be unique in the document , Similar to our ID number.
driver.find_element_by_xpath('//*[@id="su"]').click()
driver.quit()
#coding=utf-8
# Use css location
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
#html body div#wrapper div#head div.head_wrapper div.s_form div.s_form_wrapper.soutu-env-nomac.soutu-env-index form#form.fm span.bg.s_ipt_wr.quickdelete-wrap input#kw.s_ipt
driver.find_element_by_css_selector("html body div#wrapper div#head div.head_wrapper div.s_form div.s_form_wrapper.soutu-env-nomac.soutu-env-index form#form.fm span.bg.s_ipt_wr.quickdelete-wrap input#kw.s_ipt").send_keys("selenium")
# adopt id Locate the input box ,html Regulations ,id Must be unique in the document , Similar to our ID number.
driver.find_element_by_css_selector('html body div#wrapper div#head div.head_wrapper div.s_form div.s_form_wrapper.soutu-env-nomac.soutu-env-index form#form.fm span.bg.s_btn_wr input#su.bg.s_btn').click()
driver.quit()