0

Code:

from webbot import Browser
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

web = Browser()

tab = 1
add = 1

web.go_to('https://tankster.io')
time.sleep(1)

chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

driver = webdriver.Chrome(options=chrome_options)

button = driver.find_elements_by_xpath("//span[contains(text(), 'Boss vs Boss')]")
button[0].click()

text_areas = web.find_elements(xpath='//input')
web.type(web.Key.ENTER,into=text_areas[0].text)

I am getting the following error:

Traceback (most recent call last):
  File "main.py", line 22, in <module>
    button[0].click()
IndexError: list index out of range

Any help would be greatly appreciated. I am running a repl.it python environment and trying to get selenium to click on a button for me, that seems to give the error since it works fine without any selenium additions to the previous code I had. :)

Frostwolfu
  • 15
  • 5

1 Answers1

0

This is going to happen because button = driver.find_elements_by_xpath("//span[contains(text(), 'Boss vs Boss')]") Must return to you an empty list. Here is an example of that in play.

x = []
print(x[0])

Error

    print(x[0])
IndexError: list index out of range```
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44