I am trying to enter some text into a text box on a webpage, here is the screenshot screenshot for Enter Symbol .
My code works fine for all other elements except for the highlighted text box in the screenshot:
WebDriverWait(driver, 40).until(EC.visibility_of_element_located((By.XPATH, '//*[@id="main-content-column"]/div/div[3]/div/div[1]/form/div/div/div[2]/input'))).send_keys("aapl")
It doesn't look like in a frame or iframe. Please see the source 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="">
Thanks a lot.
您可以使用 xpath 输入值:
WebDriverWait(driver, 40).until(EC.visibility_of_element_located((By.XPATH, "//input[@data-ng-model='userEnteredSymbols']"))).send_keys("aapl")
You are using Absolute xpath
which is not a recommended way. You can try with below xpath
with webdriver wait
element = WebDriverWait(browser, 30).until(EC.visibility_of_element_located((By.XPATH, "//input[@data-ng-model= 'userEnteredSymbols']")))
element.send_keys("aapl")
you need below import
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.