Reputation: 59
I am currently working on a project that would make trading stocks automatic. After Logging In on the trading website, the idea is for selenium to insert the keys: "FB" into the search bar. If you do this manual suggestion for the stocks you are looking for pops up. But to my surprise, they do not show as soon as selenium takes control. I will give away the full code if anyone wants to try the program themself, just change the path to the browser! The account is fake, so don't worry... :)
Code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
browser = webdriver.Chrome('/Users/larskvist/downloads/chromedriver')
browser.get('https://www.forex.com/en-uk/account-login/')
username_elem = browser.find_element_by_name('Username')
username_elem.send_keys('[email protected]')
password_elem = browser.find_element_by_name('Password')
password_elem.send_keys('KEbababdulaziz')
password_elem.send_keys(Keys.ENTER)
search_elem = WebDriverWait(browser, 20).until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, "input.market-search__search-input")))
search_elem.send_keys('FB')
Thanks in advance!
Upvotes: 1
Views: 648
Reputation: 33384
Once you identify the element first click on the element and then provide send_keys()
browser = webdriver.Chrome('/Users/larskvist/downloads/chromedriver')
browser.get('https://www.forex.com/en-uk/account-login/')
username_elem = browser.find_element_by_name('Username')
username_elem.send_keys('[email protected]')
password_elem = browser.find_element_by_name('Password')
password_elem.send_keys('KEbababdulaziz')
password_elem.send_keys(Keys.ENTER)
search_elem = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.market-search__search-input")))
search_elem.click()
search_elem.send_keys('FB')
Browser snapshot:
Upvotes: 1
Reputation: 6459
You need to click on this input after typing "FB":
...
search_elem = WebDriverWait(browser, 20).until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, "input.market-search__search-input")))
search_elem.send_keys("FB")
time.sleep(5)
search_elem.click()
I hope it helps you!
Upvotes: 2