Home > front end >  How to get the title attribute and innerHTML from a <a> link tag in robot framework
How to get the title attribute and innerHTML from a <a> link tag in robot framework

Time:04-01

I have an HTML link

<a  href="http://automationpractice.com/index.php?id_product=7&amp;controller=product" title="Printed Chiffon Dress" itemprop="url" style="user-select: auto;">Printed Chiffon Dress</a>

I want to get the value of the title or innerHTML "Printed Chiffon Dress"

        Verify Best Sellers functionality
        Click Link  //ul[@id='home-page-tabs']//child::li[2]//a
        @{links}=  Get WebElements  //div[@class='right-block']//h5//a
        ${cnt}=    Get length    ${links}
        Log  There are ${cnt} lines in the description
    
        FOR    ${a}  IN  @{links}
              ${text}=  Get Text    ${a}
              Log  ${text}
        END

CodePudding user response:

First, you need to debug whether you get any output in @{links} if yes, then try following code

FOR ${a} IN @{links}
    Log to Console  ${a.text}
END

CodePudding user response:

Try Get Element Attribute from SeleniumLibrary

 FOR    ${a}  IN  @{links}
              ${text}=  Get Element Attribute    ${a}   title
              Log  ${text}
 END
  • Related