Search code examples
pythonseleniumexceptiontextboxstopiteration

StopIteration Error During Entering Text to Text Box


I am trying to input a long string (around 4000 characters) into a text box using Python and Selenium.

Once the full string is entered, the whole thing in the text box disappears and below error appears:

Internal StopIteration: False

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

In debug mode, I tested with send_keys("aapl"), it worked fine, but not with the long string. The loop works fine as well and provides a string including around 800 symbols separated by comma.

My code:

# 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="">```

Solution

  • So the issue is resolved. I used a generator and looped through it, not sure how, but it works now.

    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)