取得元件屬性 - daniel-qa/RobotFramework GitHub Wiki
https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Get%20Element%20Attribute
Get Text 取得文字內容
${text}= Get Text xpath=//*[@id="element_id"]
${number}= Get Text (defined location of text, minus parentheses)
取得元件屬性和文字
- 取得 href
${text} = Get Element Attribute xpath://*[@id="some_element_id"] href
以下是一個示例:
${element} Get Element //h1[@class='title'] # 使用XPath找到一個元件
${attribute} Get Element Attribute ${element} class # 獲取元件的class屬性
${text} Get Text ${element} # 獲取元件的文字
- EX
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Get Element Attribute and Text
Open Browser https://www.example.com chrome
${element} Get Element //h1[@class='title'] # 使用XPath找到一個元件
${attribute} Get Element Attribute ${element} class # 獲取元件的class屬性
${text} Get Text ${element} # 獲取元件的文字
Log Element Attribute: ${attribute}
Log Element Text: ${text}
Close Browser