Есть ли способ добавить номер перед элементом - PullRequest
0 голосов
/ 17 марта 2020

МОЙ КОД

    sidebar = self.driver.find_element_by_class_name('menusubnav')
    elementList = sidebar.find_elements_by_tag_name("li")
    for i in range(len(elementList)):
       element = self.driver.find_element_by_class_name('menusubnav').find_elements_by_tag_name("li")[i]
       print(enumerate, element.text)

======================================== РЕЗУЛЬТАТ =========================

   C:\DEV\practice\venv\Scripts\python.exe C:/DEV/practice/test_case.py
   test_guru (__main__.LoginGuruTest) ... 
   <class 'enumerate'> Manager
   <class 'enumerate'> New Customer
   <class 'enumerate'> Edit Customer
   <class 'enumerate'> Delete Customer
   <class 'enumerate'> New Account
   <class 'enumerate'> Edit Account
   <class 'enumerate'> Delete Account
   <class 'enumerate'> Deposit
   <class 'enumerate'> Withdrawal
   <class 'enumerate'> Fund Transfer
   <class 'enumerate'> Change Password
   <class 'enumerate'> Balance Enquiry
   <class 'enumerate'> Mini Statement
   <class 'enumerate'> Customised Statement
   <class 'enumerate'> Log out
   ===  Alert shows following message:  ====
   ===========================================
   ||   You Have Succesfully Logged Out!!   ||
   ===========================================
   ok
   test_screenshot_logout (__main__.LoginGuruTest) ... ok

   ----------------------------------------------------------------------
   Ran 2 tests in 28.417s

   OK

   Process finished with exit code 0

================ ================================================== ======

ХОЧУ ЭТОТ ОДИН ---- НУМЕРАЯ РЕЗУЛЬТАТ ЭЛЕМЕНТОВ СТРАНИЦЫ

================= ================================================== ===

     1. Manager
     2. New Customer
     3. Edit Customer
     4. Delete Customer
     5. New Account
     6. Edit Account
     7. Delete Account
     8. Deposit
     9. Withdrawal
     10. Fund Transfer
     11. Change Password
     12. Balance Enquiry
     13. Mini Statement
     14. Customised Statement
     15. Log out

====================================== ==========================================

Спасибо

Ответы [ 2 ]

0 голосов
/ 17 марта 2020

Уважаемый, пожалуйста, попробуйте напечатать этот код и будет работать

print(str(i + 1) +'.' +element.text)
0 голосов
/ 17 марта 2020

этого должно хватить:

for i, element in enumerate(elementList):
       print(i+1, element.text)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...