V
V
vadimeasy2021-10-14 20:34:06
Python
vadimeasy, 2021-10-14 20:34:06

List index out of range, what to do?

Hello, I ran into a problem, the program does not want to display information from the site page after I put the webdriver in the background, when the background is turned off, everything works. Here is the code:

from selenium import webdriver
import time
from art import tprint
from selenium.webdriver.chrome import options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

options = Options()
options.headless = True

url = "https://cerberus.vetrf.ru/cerberus/actualObject/pub/actualInfo/"

driver = webdriver.Chrome(chrome_options=options)

guid = str (input('Введите GUID:'))

try:
    driver.get(url=url)
    driver.find_element_by_tag_name('input').send_keys('guid')
    # driver.find_element_by_tag_name('input').send_keys('secret_key')
    driver.find_element_by_tag_name('button').click()
    print ('stage1')
    time.sleep(1)
   
    elements = driver.find_elements_by_xpath('//span[@class="label label-warning"][1]')

    
    print(elements[1].text)



    
except Exception as ex:
    print(ex)
finally:
    driver.close()
    driver.quit()

Here is what the terminal outputs:
driver = webdriver.Chrome(chrome_options=options)

DevTools listening on ws://127.0.0.1:64328/devtools/browser/878b19f1-6190-43be-93d0-584e470b70dd
Введите GUID:secret_key
stage1
list index out of range


Help solve the problem please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2021-10-14
@vadimeasy

Instead of print(elements[1].text) write print(elements). Wangyu will be None.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question