Home > Enterprise >  Get text From xpath under li and class?
Get text From xpath under li and class?

Time:02-16

I have this xpath: I want to get the number circled in the red --> see the attached image , which is the total number of pages , I did the following

[![enter image description here][1]][1]
<li  xpath="1">1 / 5>/li>

${actual_pages_nb}    Get Text    xpath://li[@class='small-screen']

but the returned text is null , i wanna get 5

CodePudding user response:

Use this XPath to get the text

//li[@]/text()

CodePudding user response:

but the returned text is null , i wanna get 5

This means that the keyword was executed without errors, so it found an element with that locator, but probably not the one you need.

The keywords return the first found element, unless you explicitly indicate the index you need.

You must find a better locator (and better to confirm with the browser developer tool, the existing o several elements with that locator).

CodePudding user response:

There are a couple of points here:

a. Is the DOM line provided correct?

<li xpath="1">1 / 5>/li> Here the /li> does not have an opening <. The li open tag closes after providing the xpath=1, then followed by the text 1 / 5> and then it is /li>, whereas it should be `.

Having said that, the code the get the text for the line as provided is:

    Open Browser        ${url}      Chrome      executable_path=${your executable path}
    Sleep       2
    ${txt} =      Get Text        class: small-screen
    Log To Console    ${txt}

Output is: 1 / 5>/li>

But if you correct the DOM (assuming like this): <li xpath="1">1 / 5</li>, then the answer would be 1 / 5

Anyway, it is the DOM that needed change, if at all a change is needed be; else, for both the scenarios, the same code would work.

  • Related