ranger
ranger

Reputation: 737

Get Element Attribute in robot framework

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.

Upvotes: 2

Views: 70309

Answers (5)

Vincent Gerris
Vincent Gerris

Reputation: 7537

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.

Upvotes: 1

Batchu Bhargava
Batchu Bhargava

Reputation: 49

You can use both XPath and CSS selector if you have selenium library

${title}=  Get Element Attribute  ${xpath}    attribute=title

Upvotes: -2

Stéphane GRILLON
Stéphane GRILLON

Reputation: 11882

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

Upvotes: 1

hakobe
hakobe

Reputation: 1

Thanks a lot, i wanted to check meta noindex content in page source.

i used this.

${content}  Get Element Attribute   xpath=//meta[@name="robots"]@content
should be equal as strings  ${content}  noindex,follow

Upvotes: 0

shicky
shicky

Reputation: 2126

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

Upvotes: 8

Related Questions