'Get text From xpath under li and class?
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 class="small-screen" 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
Solution 1:[1]
Use this XPath to get the text
//li[@class="small-screen"]/text()
Solution 2:[2]
There are a couple of points here:
a. Is the DOM line provided correct?
<li class="small-screen" 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 class="small-screen" 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Krupal Vaghasiya |
| Solution 2 | Anand Gautam |
