【问题标题】:Trying to click on button gives me an error. I am using repl.it python environment试图点击按钮给我一个错误。我正在使用 repl.it python 环境
【发布时间】:2021-04-21 01:28:34
【问题描述】:

代码:

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)

我收到以下错误:

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

任何帮助将不胜感激。我正在运行一个 repl.it python 环境并试图让 selenium 为我点击一个按钮,这似乎给出了错误,因为它工作正常,没有任何 selenium 添加到我以前的代码中。 :)

【问题讨论】:

  • 打印按钮,看看你得到了什么。

标签: python python-3.x selenium selenium-chromedriver repl.it


【解决方案1】:

这将会发生,因为button = driver.find_elements_by_xpath("//span[contains(text(), 'Boss vs Boss')]") 必须返回给您一个空列表。下面是一个例子。

x = []
print(x[0])

错误

    print(x[0])
IndexError: list index out of range```

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-13
    • 2020-02-27
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多