Selenium模擬游標進入和tab鍵移動

2021-06-19 07:10:35 字數 690 閱讀 5998

在做乙個專案的selenium測試,但是遇到乙個問題,通過tape語句輸入日期之後,到selenium執行到查詢按鈕的時候,

輸入的日期卻是不正確了。比如輸入04102013,結果卻04/02/13__。輸入04/10/2013,結果卻是04/10/20。

後來深入的研究了日期輸入框的行為,原來是系統在js上做了一些特殊的處理。游標進入時,把格式掩碼(如/)去掉,

顯示數字,游標離開之後,進行格式掩碼處理。 並且限制該輸入框的最大輸入長度為8。因此,才造成上面的幾種錯誤。

所以,我們就採用下面的作法,模擬游標的進入,賦值,游標離開。

selenium.focus("id=condition.orderno");   //id=condition

.fromdate的上乙個專案

selenium.keypressnative("09");  //模擬鍵入tab鍵

selenium.focus("id=condition

.fromdate"); // 設游標

selenium.type("id=condition

.fromdate", "04102013"); //賦值

selenium.focus("id=condition

.fromdate");  //設游標

selenium.keypressnative("09"); //模擬鍵入tab鍵

selenium 模擬滑鼠拖拽

1 從乙個元素拖拽到另乙個元素 from selenium import webdriver from selenium.webdriver import actionchains import time browser webdriver.chrome try browser.get browse...

selenium模擬滑鼠操作

perform self 執行鏈中的所有動作 reset actions self 清除儲存在遠端的動作 click self,on element none 滑鼠左鍵單擊 click and hold self,on element none 滑鼠左鍵單擊,不鬆開 context click se...

selenium模擬滑鼠滾動

target driver.find element by id id keypair driver.execute script arguments 0 scrollintoview target 拖動到可見的元素去 這個方法可以模擬滑鼠滾動到需要顯示的元素位置,使用場景 瀏覽器視窗小,頁面過大內...