1

enter image description here

I am trying to give input to the 'Currency I have' text box. This input is in the variable 'currency'. After I give the input in the text box, it displays a number of options. I want to do a case insensitive match on the 3 letter currency code I enter and the options the text box displays in the drop-down, and select the correct one. The page I am testing: https://www.oanda.com/fx-for-business/historical-rates

currency = currency_list.loc[i,'currency']
    print(f'\nFETCHING DATA FOR : {currency}')
    df=pd.DataFrame()
    
    #input our currency in "currency I have" text-box
    WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.CSS_SELECTOR,'#havePicker > div'))).click()
    currency_have = WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.CSS_SELECTOR,'#havePicker > div > input')))
    
    try:
        currency_have.clear() 
    except:
        pass
    
    currency_have.send_keys(currency)
    options = WebDriverWait(driver, 2).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,'#havePicker > div > ul li')))
    
    div_tags = [li_tags.find_elements_by_tag_name('div') for li_tags in options]
        
    for div_tag in div_tags:
        test = div_tag[1]
        if (test.text.casefold()) == (currency.casefold()):
            return test
        else:
            continue

The return statement in my code is incorrect. How do I proceed further to achieve my goal?

Please, any help would be appreciated.

vitaliis
  • 4,082
  • 5
  • 18
  • 40
Soumya Pandey
  • 321
  • 3
  • 19

1 Answers1

1

In order to wait for dropdown result, the order of your actions should be the following:

  • Clear "Currency I have" dropdown
  • Click it (not completely sure if this action is required, test it)
  • Wait for all values
  • Send value ("Australian dollar") # not AUD as there is also Saudi Riyal in search results

This part of code should look like below:

wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '#havePicker > div'))).click()
currency_have = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CSS_SELECTOR, '#havePicker > div > input')))

currency_have.clear()
currency_have.click()

options = WebDriverWait(driver, 10).until(
    EC.presence_of_all_elements_located((By.CSS_SELECTOR, '#havePicker > div > ul li')))
currency_have.send_keys("Australian dollar")

Please note that you have two results on AUD. That's why I used the full currency name. If you want to use just aud, use split() Check here how to use it How to extract the substring between two markers? Then improve your for loop.

vitaliis
  • 4,082
  • 5
  • 18
  • 40