1、文件上傳
一般的web端操作中,常見的上傳文件類型有圖片和excel等。文件上傳一般都會用到input標籤,通過name或者id定位到input標籤,用send_keys(“文件路徑+文件名”)將文件選中到上傳區域。
示例1:
find_element(By.ID,“pack”).send_keys(“文件路徑+文件名”)
示例2:
find_element(By.NAME,“titlepicfile”).send_keys(“文件路徑+文件名”)
2、網頁截圖
測試過程中,會常常用到網頁截圖,方便排查測試用例執行情況。相關api在《python+selenium自動化測試-5selenium常用API》有說明。
driver=webdriver.Firefox()
driver.get("https://www.baidu.com")
driver.save_screenshot_as_file(path+filename)