在文本框中输入文本时出现 StopIteration 错误

StopIteration Error During Entering Text to Text Box

我正在尝试使用 Python 和 Selenium 在文本框中输入一个长字符串(大约 4000 个字符)。

输入完整字符串后,文本框中的所有内容都会消失,并出现以下错误:

内部 StopIteration:假

c:\users\echo\anaconda3\lib\site-packages\ipython\core\interactiveshell.py(3058)run_cell_async() -> interactivity=interactivity, compiler=compiler, result=result)

在调试模式下,我使用 send_keys("aapl") 进行了测试,它工作正常,但不适用于长字符串。该循环也工作正常,并提供一个字符串,其中包含大约 800 个以逗号分隔的符号。

我的代码:

# Get symbols from Excel

filename = "file path"
wb1 = xl.load_workbook(filename)
ws1 = wb1.worksheets[8]
mr = ws1.max_row
symbols = ""
for i in range(2, mr + 1):
        c = ws1.cell(row = i, column = 1)
        if isinstance(c.value, str):
            symbols += f",{c.value}"
        else:
            print(c)

# Input symbols to Watchlist

WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, '//input[@data-ng-model="userEnteredSymbols"]'))).send_keys(symbols)

# The code for the website:

    <input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" placeholder="Add a symbol..." class="sec-search-box bc-form__add-symbol-input ng-pristine ng-invalid ng-invalid-required ng-touched placeholder" data-ng-model="userEnteredSymbols" data-barchart-clear-input="" required="">```

所以问题已经解决了。我使用了一个生成器并循环遍历它,不确定如何,但它现在可以工作了。

def gen_function():
l = symbols
for s in l:
    yield s
gen_obj = gen_function()

# Input symbols to Watchlist
for s in gen_obj:
    WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, '//input[@data-ng-model="userEnteredSymbols"]'))).send_keys(s)