【发布时间】: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