0

Python と Selenium を使用して、長い文字列 (約 4000 文字) をテキスト ボックスに入力しようとしています。

文字列全体を入力すると、テキスト ボックス内のすべてが消え、以下のエラーが表示されます。

内部 StopIteration: False

c:\users\echo\anaconda3\lib\site-packages\ipython\core\interactiveshell.py(3058)run_cell_async() -> 対話性 = 対話性、コンパイラ = コンパイラ、結果 = 結果)

デバッグ モードでは、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="">```
4

1 に答える 1

0

これで問題は解決しました。ジェネレーターを使用してループしましたが、方法はわかりませんが、現在は機能しています。

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)
于 2020-01-26T19:52:58.920 に答える