2017-07-06 70 views
0

我想从此下拉菜单中选择最后一个值。如何从Python下拉菜单中选择后获得价值?

<select id="VersionValue"> 
    <option value="0">Select Version</option> 
    <option value="1110.0">1110.0</option> 
    <option value="1111.0">1111.0</option> 
    <option value="1112.0">1112.0</option> 
    <option value="1113.0">1113.0</option> 
    <option value="1114.0">1114.0</option> 
</select> 

我在Python代码来获得最后的下拉菜单

select = Select(driver.find_element_by_id("VersionValue")) 
    selectLen = len(select.options) 
    select.select_by_index(selectLen - 1) 

我如何从价值下拉菜单中选择与Python后? 我使用硒库for python。

+0

什么是你有什么问题? – Guy

回答

0

你有first_selected_option,选择价值

option = select.first_selected_option 

这将返回选项的webelement后使用。要获取值使用

option.text 

或者

option.get_attribute("value") 
+0

我使用这个解决方案,并且出现错误“TypeError:'WebElement'object is not callable” – Aidento

+0

@Aidento删除括号。 – Guy

+0

我也尝试过使用“select.first_selected_option”,我得到的值是selenium.webdriver.remote.webelement.WebElement(session =“1231213-123-4bff-12qws1-bdd64a123123”,element =“qwewd123-qweq-40e3-1223 -qwesq23123“)> – Aidento

0

这里是回答你的问题:

select = Select(driver.find_element_by_id("VersionValue")) 
select.select_by_value("1114.0") 

让我知道如果这个回答你的问题。

相关问题