Riaz Ladhani
Riaz Ladhani

Reputation: 4062

Selenium Webdriver Python how to get the selected value from a disabled drop down

I have come across a disabled drop down. I am trying to get the selected value from the drop down. I would like to find out what value has been selected in the drop down.
I get the following error when i run my code:

datamap_dropdown_value = datamapdropdown_value.first_selected_option()
TypeError: 'WebElement' object is not callable

The method implementation is:

def get_datamap_dropdown_field_value(self):
    datamapdropdown_value = Select(self.driver.find_element(By.ID, 'match_configuration_edit_match_lb_datamaps))
    datamap_dropdown_value = datamapdropdown_value.first_selected_option()
    print datamap_dropdown_value
    return datamap_dropdown_value

The method is called from here:

# Check name, datamap dropdown fields from details tab have saved correctly
def verify_matches_details_tab_fields_have_saved(self, name):
    name_field_value = self.get_name_field_value(name)
    datamap_dropdown_value = self.get_datamap_dropdown_field_value()
    return (name_field_value == name) and (datamap_dropdown_value == self.datamap_name)

The HTML is:

<div class="clear">
    <span class="gwt-InlineLabel marginbelow myinlineblock" style="width: 8em;">Datamap</span>
        <select id="match_configuration_edit_match_lb_datamaps" class="gwt-ListBox marginbelow" style="display: inline;" disabled="">
            <option value="ceb09_16_1512_26_23">ceb09_16_1512_26_23</option>
        </select>
</div>

Thanks, Riaz

Upvotes: 2

Views: 978

Answers (1)

Mesut GUNES
Mesut GUNES

Reputation: 7401

you can get the value of the element by calling text like driver.find_element_by_id("match_configuration_edit_match_lb_datamaps").text

>>> elm = driver.find_element_by_id("match_configuration_edit_match_lb_datamaps")
>>> print elm.text
ceb09_16_1512_26_23

Upvotes: 1

Related Questions