2015-10-06 97 views
2

我遇到了禁用的下拉菜單。我正在嘗試從下拉菜單中獲取選定的值。我想知道在下拉菜單中選擇了什麼值。
我收到以下錯誤,當我運行代碼:Selenium Webdriver Python如何從禁用的下拉菜單中獲取選定的值

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

的方法實現:

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 

的方法就是從這裏稱爲:

# 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) 

的HTML是:

<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> 

謝謝, 里亞茲

回答

1

您可以通過調用文字像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 
+0

這個工程得到了元素的值。非常感謝。 –

相關問題