1、结合unittest以及元素定位的8方法,编写具体的测试用例
from selenium import webdriver from selenium.webdriver.common.by import By import time as t '''id的定位''' driver=webdriver.Chrome() driver.get('http://www.baidu.com') driver.find_element_by_id('kw').send_keys("Hellow World") t.sleep(5) '''name的定位''' # driver=webdriver.Chrome() # driver.get('http://www.baidu.com') # driver.find_element_by_name('wd').send_keys("Hellow World") # t.sleep(5) '''class_name的定位''' # driver=webdriver.Chrome() # driver.get('http://www.baidu.com') # driver.find_element_by_class_name('s_ipt').send_keys("Hellow World") # t.sleep(5) '''xpath的定位''' # driver=webdriver.Chrome() # driver.get('http://www.baidu.com') # driver.find_element_by_xpath('//*[@id="kw"]').send_keys("Hellow World") # t.sleep(5) '''css定位''' # driver=webdriver.Chrome() # driver.get('http://www.baidu.com') # driver.find_element_by_css_selector('#kw').send_keys("Hellow World") # t.sleep(5) '''LINK_TEXT''' # driver=webdriver.Chrome() # driver.get('http://www.baidu.com') # driver.find_element_by_link_text('直播').click() # t.sleep(5) '''PARYIAL_LINK_TEXT''' # driver=webdriver.Chrome() # driver.get('http://www.baidu.com') # driver.find_element_by_partial_link_text('播').click() # t.sleep(5)
2、通过实际的案例来演示单个元素定位和多个元素的方式