0

I'm working with selenium in python and in this web page I want to choose between different options in a drop down menu and then enter some values. In that webpage, after I click on the "new order" button, a new windows pops up and I have to choose between symbols, for example, "USDCAD". After that I have to enter some values such as "take profit" and "stop loss". I don't know how to do these because unfortunately I don't know much about how web pages work and what HTML is and...! This is the code that I wrote for selecting between drop down menu options but I get error:

def fast_multiselect(driver, element_id, labels):
    select = Select(driver.find_element_by_id(element_id))
    for label in labels:
        select.select_by_visible_text(label)
fast_multiselect(driver, 'symbol', "USDCAD")

And this is the error that I get:

selenium.common.exceptions.UnexpectedTagNameException: Message: Select only works on <select> elements, not on <th>

Complete code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome('./chromedriver')
driver.get('https://www.mql5.com/en/trading')
time.sleep(10)
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@id='webTerminalHost']")))
time.sleep(10)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@title='New Order']/span"))).click()
time.sleep(5)
def fast_multiselect(driver, element_id, labels):
    select = Select(driver.find_element_by_id(element_id))
    for label in labels:
        select.select_by_visible_text(label)
fast_multiselect(driver, 'symbol', "USDCAD")

I will be so thankful if you help me choose from the drop down menu and enter those values. And also if you explain some important and basic things or if a quick guide (maybe a useful link) which helps me understand how I should deal with HTML codes for basic jobs like my question.

1
  • It seems you got the wrong select tag identicator. Commented Nov 17, 2020 at 9:23

1 Answer 1

1

You need to target a select tag.

<select class="input-combobox" id="order-dialog-symbol">
<option value="USDCAD">USDCAD, US Dollar vs Canadian Dollar</option>

The bottom would work

fast_multiselect(driver, 'order-dialog-symbol', ["USDCAD"])

If you replaced

select.select_by_visible_text(label)

with

select.select_by_value(label)
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your reply. it gives me this error: selenium.common.exceptions.NoSuchElementException: Message: Cannot locate option with value: U
Check the fix now.fast_multiselect(driver, 'order-dialog-symbol', ["USDCAD"]) Handles multiple values now.
Where can I found this source code? : <select class="input-combobox" id="order-dialog-symbol">
But it gives me: <select class="input-combobox" id="symbol" style="position: absolute; left: 410px; width: 323px; top: 22px;"> And the id="symbol", but the id you wrote is "order-dialog-symbol"
Ok go to the developer tools-> ctrl-f -> <select> . When you go through them one will highlight over the page as the one you want. id='symbol' isn't valid for anything but a th which isn't clickable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.