Mat*_*Cox 12 python selenium selecteditem selected selenium-webdriver
如何使用Selenium WebDriver和Python获取所选选项:
有人有解决方案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"
Run Code Online (Sandbox Code Playgroud)
是否存在类似于或类似于'getFirstSelectedOption'的内容,如下所示:
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"
Run Code Online (Sandbox Code Playgroud)
然后我想用以下内容验证内容getText:
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"
Run Code Online (Sandbox Code Playgroud)
ale*_*cxe 29
这selenium使得它易于处理 - Select班级:
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16246 次 |
| 最近记录: |