1、如何去掉readonly屬性
前端對於時間控件的設置,有時是為了限制用戶不能進行手動輸入方式進行選擇時間,避免在手動輸入的時候超限或者輸入格式不正確,導致一些不必要的驗證麻煩,這是前端開發工程師就會在前端代碼中加入readonly屬性,但是對於手動測試來說的話,這種只能進行點擊控件進行選擇時間,而對於自動測試來說,這樣的方式可能是行不通,因為這個需要認證時間控件的有效性很多個選擇,自動化變得更加麻煩, 是不是就沒有辦法進行了呢?答案是否點的,例如:


那該怎么進行設置呢?這個是前人踩過的坑,后來推薦去看robotframework論壇中一篇文檔,正好能對該方式正式解決,第一需要進行設置臨時id,第二使用臨時id進行重新賦值,第三進行刪除readonly屬性
1 這是個不可以輸入的日歷控件,下面講解如何變可輸入 2 1.通過Assign Id To Element 關鍵字配臨時ID。 3 例如:Assign Id To Element | loactor | 臨時ID 4 2.用Execute JavaScript 方法: 5 window.document.getElementById('臨時ID').value='2016-12-19' 6 7 經過實踐:下面直接去除readonly屬性再輸入OK 8 window.document.getElementById('臨時ID').removeAttribute("readonly")
1 [Setup] 登錄 2 詢價打開模塊公共方法 3 詢價高級查詢按鈕 4 Comment Click Element xpath=.//*[@id='CreatedDate1'] 5 sleep 5 6 Comment Unselect Frame 7 Comment Select Frame id=InquiryAndProject_Residential 8 Comment ${a} Get Text /html/body/div[9]/div[1]/div[3] 9 Comment log ${a} 10 Comment Input Text xpath=//div[@class='date-picker-wrapper no-shortcuts no-gap two-months' and contains(@style,'display: block')]//div[@class='normal-top']/b[1] 2017-01-20 11 Comment Input Text xpath=.//*[@id='CreatedDate1'] 2017-01-20 至 2017-02-18 12 Assign Id To Element xpath=.//*[@id='CreatedDate1'] new_time 13 Assign Id To Element xpath=.//*[@id='CreatedDate1From'] new_time1 14 Assign Id To Element xpath=.//*[@id='CreatedDate1To'] new_time2 15 Execute JavaScript window.document.getElementById('new_time').value='2017-01-15 至 2017-01-20' 16 Execute JavaScript window.document.getElementById('new_time1').value='2017-01-15' 17 Execute JavaScript window.document.getElementById('new_time1').value='2017-01-15' 18 Execute JavaScript window.document.getElementById('new_time2').value='2017-01-20' 19 Execute JavaScript window.document.getElementById('new_time').removeAttribute("readonly") 20 詢價查詢按鈕
2、進行自動化手動選擇控件


1 按蓋章時間查詢 2 Set Selenium Speed 0.5 3 登錄 4 點擊我的項目 5 點擊項目蓋章 6 Select Frame id=ProjectAllot_Seal 7 等待列表加載完成 1 8 點擊已蓋章 9 等待列表加載完成 2 10 Comment 按輸入時間查詢 2015-5-28 2019-6-9 11 ${start_date} Set Variable 2016-12-1 12 ${end_date} Set Variable 2017-1-10 13 按單個時間查詢 ${start_date} //td[@id='sealTime']/span/span 14 按單個時間查詢 ${end_date} //td[@id='sealTime2']/span/span 15 ${min_stamp} Get Stamp ${start_date} 16 ${max_stamp} Get Stamp ${end_date} 17 點擊查詢 2 18 ${no} get總頁數 2 19 ${no} Run Keyword If ${no}<10 Set Variable ${no} 20 ... ELSE Set Variable 10 21 : FOR ${i} IN RANGE 10 22 \ Wait Until Element Is Visible //div[@id='tabs']/div[2]/div[2]//div[@class='datagrid-view2']/div[2]//tbody/tr[${i+1}] 10 23 \ ${result} Get Text //div[@id='tabs']/div[2]/div[2]//div[@class='datagrid-view2']/div[2]//tbody/tr[${i+1}]/td[8]/div 24 \ ${list} Evaluate '${result}'.split(' ') 25 \ ${date} Evaluate ${list}[0] 26 \ ${arr} Evaluate '${date}'.split('/') 27 \ ${current_date} Evaluate '-'.join(${arr}) 28 \ ${current_stamp} Get Stamp ${current_date} 29 \ Should Be True ${current_stamp}>=${min_stamp} and ${current_stamp}<=${max_stamp} 已蓋章頁面按照蓋章時間查詢不正確
1 按單個時間查詢 2 [Arguments] ${input_date} ${DropBtn_xpath} 3 [Documentation] 輸入: 4 ... 5 ... 1、${input_date}:輸入的日期參數,格式為2016-2-3 ,個位數不補0,不能寫為2016-02-03 6 ... 7 ... 2、${dropBtn_xpath}:日期控件的下拉按鈕xpath路徑 8 Set Selenium Speed 0.5 9 ${prevAndAfter} Set Variable 0 #0表示向前翻,1表示向后翻 10 ${base_path} Set Variable //div[@class='panel combo-p' and contains(@style,'display: block')] 11 ${dict} Create Dictionary 1=一月 2=二月 3=三月 4=四月 5=五月 12 ... 6=六月 7=七月 8=八月 9=九月 10=十月 11=十一月 13 ... 12=十二月 14 ${prev_month} Set Variable ${base_path}//div[contains(@class,'calendar-prevmonth')] #點擊上一個月 15 ${prev_year} Set Variable ${base_path}//div[contains(@class,'calendar-prevyear')] 16 ${next_year} Set Variable ${base_path}//div[contains(@class,'calendar-nextyear')] 17 ${next_month} Set Variable ${base_path}//div[contains(@class,'calendar-nextmonth')] 18 ${input_date} Set Variable '${input_date}'.split('-') 19 ${start_abbr} Evaluate ','.join(${input_date}) #匹配要點擊開始哪天的abbr屬性 20 ${s_year} Evaluate ${input_date}[0] 21 ${s_month} Evaluate ${input_date}[1] 22 ${s_day} Evaluate ${input_date}[2] 23 ${startDayPath} Set Variable ${base_path}//td[text()=${s_day} and @abbr='${start_abbr}'] #需要點擊的開始day 24 ${s_year} Evaluate int('${s_year}') 25 ${s_month} Evaluate int('${s_month}') 26 ${s_day} Evaluate int('${s_day}') 27 Click Element ${DropBtn_xpath} #點擊開始時間下拉按鈕 28 ${current_ym} Set Variable ${base_path}//div[contains(@class,'calendar-title')]/span #當前年月 29 ${yearAndMonthStr} Get Text ${current_ym} 30 ${yearAndMonthArr} Evaluate u'${yearAndMonthStr}'.split(' ') 31 ${current_year} Evaluate ${yearAndMonthArr}[1] 32 ${current_month} Evaluate ${yearAndMonthArr}[0] 33 ${year_no} Evaluate int('${current_year}') #當前年份 34 ${keys} Get Dictionary Keys ${dict} 35 ${values} Get Dictionary Values ${dict} 36 ${v_len} Evaluate len(${values}) 37 : FOR ${i} IN RANGE ${v_len} 38 \ ${temp} Evaluate ${values}[${i}] 39 \ ${month_no} Run Keyword If '${current_month}'=='${temp}' Evaluate ${keys}[${i}] 40 \ Exit For Loop If '${current_month}'=='${temp}' 41 ${month_no} Evaluate int('${month_no}') #當前月份 42 #確定要翻幾年 43 ${yearTurnCount} Evaluate ${s_year}-${year_no} 44 ${prevAndAfter1} Run Keyword If ${yearTurnCount}>0 Set Variable 1 45 ... ELSE Set Variable 0 46 ${yearTurnCount} Evaluate abs(${yearTurnCount}) 47 #確定要翻幾月 48 ${monthTurnCount} Evaluate ${s_month}-${month_no} 49 ${prevAndAfter2} Run Keyword If ${monthTurnCount}>0 Set Variable 1 50 ... ELSE Set Variable 0 51 ${monthTurnCount} Evaluate abs(${monthTurnCount}) 52 : FOR ${i} IN RANGE ${yearTurnCount} 53 \ Run Keyword If ${prevAndAfter1}==0 Click Element ${prev_year} 54 \ ... ELSE Click Element ${next_year} 55 : FOR ${i} IN RANGE ${monthTurnCount} 56 \ Run Keyword If ${prevAndAfter2}==0 Click Element ${prev_month} 57 \ ... ELSE Click Element ${next_month} 58 Click Element ${startDayPath}
1 清空選擇的日期 2 [Arguments] ${dropBtn_xpath} 3 [Documentation] 輸入: 4 ... 1、${dropBtn_xpath}:日期控件的下拉按鈕xpath路徑 5 Click Element ${dropBtn_xpath} 6 ${base_path} Set Variable //div[@class='panel combo-p' and contains(@style,'display: block')] 7 Click Element ${base_path}//a[text()='清空']
