1:附上test_locator包的部分代码(个人觉的locator封装不一定要全部locator包,有些以元素定位表达式驱动用例的部分可以把元素定位放进test_page包)
from selenium.webdriver.common.by import By class AddressManageLocator: add_new_address_loc=(By.XPATH,"//input[@value='+添加新的地址']") table_loc=(By.XPATH,"//table[@width='100%']") #tr元素 column_loc=(By.XPATH,"//table[@width='100%']//tbody//tr") #修改地址 modify_address_loc=(By.XPATH,"//img[@src='/Public/Home/Default/images/edit.png']") #收货地址文本 receipt_address_text_loc=(By.XPATH,"//span[text()='编辑收货地址']") #收货人 receipt_person_loc=(By.ID,"consigneeName") #详细地址 detail_address_loc=(By.ID,"consigneeAddress") #联系方式 contact_mobile_loc=(By.ID,"consigneeMobile") #邮编 post_code_loc=(By.ID,"consigneeEmail") #保存收货地址 save_address_loc=(By.XPATH,"//a[text()='保存收货地址']") detail_address_text_loc=(By.XPATH,"//table[@width='100%']//tbody//tr[2]//td[2]") post_code_text_loc=(By.XPATH,"//table[@width='100%']//tbody//tr[2]//td[3]") receipt_person_text_loc=(By.XPATH,"//table[@width='100%']//tbody//tr[2]//td[4]") contact_mobile_text_loc=(By.XPATH,"//table[@width='100%']//tbody//tr[2]//td[5]") #省市 town_loc=(By.ID,"town") xu_hui_loc = (By.XPATH, "//option[@value='2706']")
from selenium.webdriver.common.by import By class AddAddressLocator: add_address_text_loc=(By.XPATH,"//span[text()='新增地址']") province_loc=(By.ID,"province") city_loc=(By.ID,"city") town_loc=(By.ID,"town") #上海市321 shang_hai_loc=(By.XPATH,"//option[@value='321']") #徐汇区 xu_hui_loc=(By.XPATH,"//option[@value='2706']") detail_address_loc=(By.XPATH,"//input[@name='address']") contact_loc=(By.XPATH,"//input[@name='contact']") contact_information_loc=(By.XPATH,"//input[@name='contact_number']") postal_code_loc=(By.XPATH,"//input[@name='postal_code']") #是单选框 default_address_loc=(By.XPATH,"//input[@value='1']/following-sibling::span") #否单选框 not_default_address_loc=(By.XPATH,"//input[@value='0']/following-sibling::span") remarks_loc=(By.XPATH,"//div[@style='width: 100%;height: 40px;border: 1px solid lightgrey;']") back_loc=(By.XPATH,"//input[@value='返回']") submit_loc=(By.XPATH,"//input[@value='确定']") success_query_loc=(By.CLASS_NAME,"error")