我目前在编写一种方法时遇到了一些困难,该方法允许我在 Select 元素中找到当前选定选项的值。
<select id="select_foo_bar">
<option value="0">FOO</option>
<option value="1" selected="selected">BAR</option>
<option value ="2">FOOBAR</option>
</select>
目前我有这个:
def find_selected_option(self):
self.wait.until(EC.presence_of_element_location((By.ID, "select_foo_bar"))
option = Select(self.driver.find_element_by_id("select_foo_bar")).first_selected_option()
return option.get_attribute("value")
据我了解,该方法将找到option
元素,获取value
并返回它。
不幸的是,我收到了错误TypeError: 'WebElement' object is not callable
。这是option = Select(self.driver.find_element_by_id("select_foo_bar")).first_selected_option()
在线上发生的。它甚至没有达到return
声明的重点。
任何帮助将不胜感激。