Pages - Menu

2019年10月31日 星期四

[Katalon Studio]輸入文字至欄位

前言

再來這個是比較常用到的地方,
在文字方塊中輸入要查詢的料號,會有兩種方式,由原始碼判斷要哪種
1.使用webUI的方式輸入文字至欄位
2.使用selenium 輸入文字至欄位


正文


1.使用webUI的方式輸入文字
先看一下要輸入的目標原始碼長什麼樣子(Fig. 1),ID 看來是固定的不會變動,好處理

(Fig. 1)
在Object Repository 增加 TestObject (Fig. 2)

(Fig. 2)
在Selected Locator 輸入 xpath(Fig. 3)

(Fig. 3)
在Script上寫(findTestObject後面接資料夾跟名稱要上面設定的一樣)。

WebUI.setText(findTestObject('Page_Windchill/input__null___keywordkeywordField_SearchTextBox___textbox'), '790-155-00')

2.使用selenium 輸入文字
這次的目標原始碼比較麻煩點(Fig. 4),沒有固定的ID,只能從其他地方開始著手了。

(Fig.4)
只要xpath湊的出來都好解決,可以先在瀏覽器上用$X()測試,檢查xpath跟selectors的方式

直接在script上寫

selenium.type('xpath=.//*[contains(@ng-repeat,"item in group.content")][1]//td[4]//input',item_no)

其他用法如下

selenium.type(‘ID=xxx’,item_no)
selenium.type(‘name=xxx’,item_no)
selenium.click(‘link=xxx’)   xxx = 連結文字

selenium的用法可以直接從katalon recorder 選擇export 看Katalon Studio的程式(Fig. 5)

(Fig. 5)

ref.
[WebUI] Set Text
開源/免費界面自動化測試工具對比研究-Selenium

沒有留言:

張貼留言