2

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.
1
  • Please edit the question and format it. Commented Jun 22, 2016 at 10:26

5 Answers 5

8

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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

Comments

1

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.

Comments

0

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

Comments

-2

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.