Get Element Attribute in robot framework

42,358

Solution 1

I think you're pretty close. Please try to format your question better, I took a quick shot because your question is difficult to read. The result will be more and better help from the community

${RADIO_XPATH}    //*[@id="${check_radio_xpath}"]
${CLASS}=    Selenium2Library.Get Element Attribute    ${check_radio_xpath}@class

Solution 2

sample for this <div><label for="foo"></label></div>

${for_value}=   Get Element Attribute  xpath=//div/label  for
Log To Console  ${for_value}

console result is:

foo

Solution 3

This snippet works for me :

Get Line Numbers And Verify
    ${line_number1}=    Get Element Attribute   //*[@id="file-keywords-txt-L1"] data-line-number
    Log To Console  ${line_number1}
    ${line_number2}=    Get Element Attribute   //*[@id="file-keywords-txt-L2"] data-line-number
    Log To Console  ${line_number2}
    Verify in order of ${line_number1} and ${line_number2} is true

What was important is that the spaces/tabs between the keywords are correct, otherwise it does not get recognised as a so called keyword.

Share:
42,358
ranger
Author by

ranger

Updated on August 18, 2021

Comments

  • ranger
    ranger almost 3 years

    hi how to use Get Element Attribute in Robot framework? in instruction I have Return value of element attribute.

    attribute_locator consists of element locator followed by an @ sign and attribute name, for example element_id@class.

    I have this xpath=${check_radio_xpath}@class is this right way? where ${check_radio_xpath} = md-radio-11

    I get this error:

    ${ischecked} = Selenium2Library . Get Element Attribute xpath=${check_radio_xpath}@class
    
    Documentation:
    Return value of element attribute.
    
    TRACE   Arguments: [ 'xpath=md-radio-11@class' ]        
    DEBUG   Finished Request    
    FAIL    ValueError: Element 'xpath=md-radio-11' not found.
    
  • shicky
    shicky about 8 years
    so this was your problem and it solved it or you solved it by other means? If my answer is correct, please accept it. If you solved it a different way, please answer your own question.