Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用带Python的SeleniumWebDriver获取所选选项?_Python_Selenium_Selenium Webdriver_Selecteditem_Selected - Fatal编程技术网

如何使用带Python的SeleniumWebDriver获取所选选项?

如何使用带Python的SeleniumWebDriver获取所选选项?,python,selenium,selenium-webdriver,selecteditem,selected,Python,Selenium,Selenium Webdriver,Selecteditem,Selected,如何使用带Python的Selenium WebDriver获取选定选项: 有人有一个getFirstSelectedOption的解决方案吗 我用这个来获取select元素: try: FCSelect = driver.find_element_by_id('FCenter') self.TestEventLog = self.TestEventLog + "<br>Verify Form Elements: F Center Select found" exce

如何使用带Python的Selenium WebDriver获取选定选项:

有人有一个
getFirstSelectedOption
的解决方案吗

我用这个来获取select元素:

try:
    FCSelect = driver.find_element_by_id('FCenter')
    self.TestEventLog = self.TestEventLog + "<br>Verify Form Elements: F Center Select found"
except NoSuchElementException:
    self.TestEventLog = self.TestEventLog + "<br>Error: Select FCenter element not found"

这是
selenium
易于处理的东西-类:

try:
    FCenterSelectedOption = FCenterSelect.getFirstSelectedOption()
    self.TestEventLog = self.TestEventLog + "<br>Verify Form Elements: F Center Selected (First) found"
except NoSuchElementException:
    self.TestEventLog = self.TestEventLog + "<br>Error: Selected Option element not found"
try:
    FCenterSelectedOptionText = FCenterSelectedOption.getText()
    self.TestEventLog = self.TestEventLog + "<br>Verify Form Elements: FCenter Selected Option Text found"
except NoSuchElementException:
    self.TestEventLog = self.TestEventLog + "<br>Error: Selected Option Text element not found"

if FCenterSelectedOptionText == 'F Center Option Text Here':
    self.TestEventLog = self.TestEventLog + "<br>Verify Form Elements: F Center Selected Option Text found"
else:
    self.TestEventLog = self.TestEventLog + "<br>Error: F Center 'Selected' Option Text not found"
from selenium.webdriver.support.select import Select

select = Select(driver.find_element_by_id('FCenter'))
selected_option = select.first_selected_option
print selected_option.text