键盘输入常规操作。
以下的范例包含:
1.python 元素定位 by.id,by.xpath(如果想要明白怎么使用xpath定位可以先学习xpath https://www.runoob.com/xpath/xpath-tutorial.html)
2.python 的键盘操作 sendkey
3.等待等(有时候页面中报错说元素定位不到,但是排除定位路径错误之后,可能就是等待时延不够,需要设置等待,三种等待方式),
class Creatpr():
def __init__(self,driver,vendornumber,itemnumber,qty):
self.driver =driver
self.vendornumber = vendornumber
self.itemnumber = itemnumber
self.qty = qty
def Creat_Pr(self):
drive= self.driver
vendornumber = self.vendornumber
itemnumber = self.itemnumber
qty = self.qty
drive.get("xxx")
drive.implicitly_wait(20)
drive.find_element_by_id("UserName").send_keys("xxxx")
drive.find_element_by_id("Password").send_keys(u'xxxx')
drive.find_element_by_id("sign_button").send_keys(Keys.ENTER)
drive.find_element_by_link_text("with AD").click()
wait = WebDriverWait(drive, 70)
wait.until(EC.presence_of_element_located((By.XPATH,"//*[@id='nc3-framework-mainview']/pr-form/div/div[1]/vendor-input/po-section/div/div[2]/form/div[1]/div/input"))).send_keys(vendornumber)
drive.find_element_by_xpath("//div[@class='icon-container ng-star-inserted']/span").click()
WebDriverWait(drive, 70, 0.5).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='itemNumberInput']"))).send_keys(itemnumber)
drive.find_element_by_xpath("//input[@id='itemNumberInput']").send_keys(Keys.ENTER)
WebDriverWait(drive, 100, 0.5).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='ng-touched ng-dirty ng-star-inserted ng-valid']/kendo-numerictextbox[@formcontrolname='wh07Qty']/span/input"))).send_keys(qty)
drive.find_element_by_xpath("//div[@class='eta-picker']/kendo-datepicker/span/kendo-dateinput/span/input").send_keys( Keys.BACK_SPACE, Keys.BACK_SPACE, "10", "11", "2020")
drive.find_element_by_xpath("//div[@class='nk-function-zone']/div[@class='nk-function-item']/button").click()
WebDriverWait(drive, 200, 0.5).until(EC.element_to_be_clickable((By.XPATH, "//pr-notification-center-dialog/kendo-dialog/div[2]/kendo-dialog-actions/button[1]"))).click()
drive.find_element_by_xpath("//div[@class='function-panel']/div[@class='nk-function-zone']/div[1]/button").click()
WebDriverWait(drive, 1500, 1).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//kendo-tabstrip/ul[@role='tablist']/li[2]/span"))).click()
ponumber=drive.find_element_by_xpath("//div[@class='k-grid-content k-virtual-content']/div/table/colgroup/tbody/tr[1]/td[1]/a").text()
print( 'final Ponumber is: '+ponumber)
def Pr_out(self):
self.driver.quit()
```python
在这里插入代码片