问题:
1.首先将 单据编号为:20210331008,删除
2.在单据编号里输入:20210331008,查询,确认这张单据已被删除
3.在删除单据编号 : 20210331005,
4.重复第2个步骤
怎么将这个单据编号查询,改为参数化
代码如下:
-- coding: utf-8 --
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
class Person:
#构造函数
def init(self,username,password):
self.username = username
self.password = password
#登录
def login(self):
self.driver = webdriver.Chrome()
self.driver.implicitly_wait(10)
#浏览器最大化
self.driver.maximize_window()
self.driver.get("http://10.1.1.9:602/Home/Index")
self.driver.find_element_by_id("FUsername").send_keys(f"{self.username}")
self.driver.find_element_by_id("FUserPassword").send_keys(f"{self.password}")
self.driver.find_element_by_id("submit").click()
sleep(10)
#返回实例一个对象,为了调用后续方法
return self
#点击单据
def click_documents(self):
#点击调休
self.driver.find_element_by_partial_link_text("销假").click()
sleep(3)
#切换到frame
self.driver.switch_to.frame("iframeBox")
return self
#查询操作
def click_search(self):
search = self.driver.find_element_by_id('btnSearch')
search.click()
return self
#清除操作
def click_remove(self):
clear = self.driver.find_element_by_id('btnClear')
clear.click()
return self
#点击复选框
def clcik_checkbox(self):
inputs = self.driver.find_elements_by_name('chkid')
for input in inputs:
if input.get_attribute('type') == 'checkbox':
inputs[1].click()
return self
#点击删除操作
def clcik_delete(self):
#点击删除
self.driver.find_element(By.XPATH,'//*[@id="tbar_remove"]/span[2]').click()
sleep(2)
#弹窗
alert = self.driver.find_element(By.XPATH,'//*[@id="layui-layer1"]/div[2]')
print(alert.text)
#点击确定
element1 = self.driver.find_element(By.XPATH,'//*[@id="layui-layer1"]/div[3]/a[1]')
element1.click()
return self
#点击查询
def search(self):
self.driver.find_element_by_id('FBillNo').send_keys("20210331008")
sleep(3)
return self
HGF = Person(‘14752’,‘1’)
HGF.login().click_documents().click_remove().click_search().clcik_checkbox().clcik_delete().search()
怎么将 这个方法写成活的,不然每次要输入单据编号才可以
def search(self):
self.driver.find_element_by_id(‘FBillNo’).send_keys(“20210331008”)
sleep(3)
return self