Loop reverse selenium python

0

I'm trying to loop back my list of li in selenium and it's not rolling. I already tried a reversed in the list but the error.

I want to loop the last li to the first one.

For example, in the list below:

<ul id="lista">
    <li>Eu nao</li>
    <li>Consigo</li>
    <li>Comecar de baixo pra cima</li>
</ul>

I would like the result to be from the bottom up. The output would have to be this way:

Comecar de baixo pra cima
Consigo
Eu nao

Note: I can not loop first on the transforming elements in the list and then do the reversed. For in my real case, the li list is approximately 5000 items. But the most current ones are always the last ones, so it does not roll to make a looping in 5000 items, turning them into a list and then in a second looping to pick up the last.

    
asked by anonymous 01.09.2017 / 18:54

1 answer

0

I'm really not realizing the problem that is happening to you, it would help if you added your code, but here's an example:

from selenium import webdriver

driver = webdriver.PhantomJS()
driver.get('https://pt.wikipedia.org/wiki/Transportes_de_Lisboa')
lis = driver.find_elements_by_css_selector('#toc ul li')
for item in reversed(lis):
    print(item.text)

Note: My driver ( PhantomJS ) may not be the same as yours, it fits the one you are using.

    
01.09.2017 / 19:13