如何善用Selenium IDE 變數功能

如何善用Selenium IDE 變數功能

這篇文章主要說明如何運用Selenium IDE  儲存變數的功能,介紹兩種使用情境

情境1. 如何利用變數儲存 Xpath,之後再利用該變數做網頁元件的定位?

情境2. 如何儲存網頁特定元件的屬性值?

我們將用Google 為範例做介紹

Google Page

 

 

情境1: 儲存網頁元件值

我們要如何找到 “Google Search”的按鈕,並且儲存 “Google Search”的值呢?

我們只要定位該網頁元件 name = “btnK”,再將該 Value= “Google Search”儲存到變數

<input type=”submit jsaction=”sf.chk name=”btnK aria-label=”Google Search value=”Google Search/>

Store Attribute Value

我們使用一個指令 storeAttribute

透過Xpath 告訴這個指令我們要儲存的屬性值為何?

xpath=//*[@name=’btnK’]@value

 

 

情境2: Xpath 變數輸入

變數是否可以儲存 Xpath 讓,再利用這個變數進行網頁的定位?

使用store 這個指令,先把 Xpath 儲存到變數 SearchXpath即可

Xpath Variable

 

Leave a Reply

Your email address will not be published. Required fields are marked *