蓝色天空网 · mbsky.com
元素操作:值、属性、选中和返回
使用真实交互验证表单结果。
固定本地测试页的实际浏览器结果,不是在线Python解释器。下载代码后可在独立环境修改输入并重新运行。
本章Python入口 · 完整实验实现 · 本站测试服务 · 本站页面交互

当前输入实际检查
| 实际检查 | 结果 |
|---|---|
| fixture-initial-no-severe-errors | 通过 |
| clear-and-send | 通过 |
| attribute-property-fallback | 通过 |
| DOM-original-attribute | 通过 |
| visible-text-only | 通过 |
| checkbox-selected | 通过 |
| checkbox-unselected | 通过 |
| radio-exclusive | 通过 |
| radio-repeat-stays-selected | 通过 |
| select-text | 通过 |
| select-value | 通过 |
| select-index | 通过 |
| multi-selected | 通过 |
| multi-deselected | 通过 |
| Select-needs-native-tag | 通过 |
| real-button-click | 通过 |
| screenshot-saved-actual-browser | 通过 |
| PNG-magic-actual-browser | 通过 |
| PNG-extent-actual-browser | 通过 |
| all-created-sessions-quit | 通过 |
本章完整入口
from selenium_lab import *
@case('selenium-ele-operator')
def elements(l,d,b,s):
el=d.find_element(By.ID,'username');el.send_keys('old');el.clear();el.send_keys('mbsky');l.eq('clear-and-send',el.get_property('value'),'mbsky');a=d.find_element(By.ID,'attribute');a.clear();a.send_keys('changed');l.eq('attribute-property-fallback',a.get_attribute('value'),'changed');l.eq('DOM-original-attribute',a.get_dom_attribute('value'),'initial');l.eq('visible-text-only',d.find_element(By.ID,'visible-text').text,'看得见的正文');click(d,'subscribe');l.check('checkbox-selected',d.find_element(By.ID,'subscribe').is_selected());click(d,'subscribe');l.check('checkbox-unselected',not d.find_element(By.ID,'subscribe').is_selected());click(d,'mobile');l.check('radio-exclusive',d.find_element(By.ID,'mobile').is_selected()and not d.find_element(By.ID,'web').is_selected());click(d,'mobile');l.check('radio-repeat-stays-selected',d.find_element(By.ID,'mobile').is_selected());select=Select(d.find_element(By.ID,'topic'));select.select_by_visible_text('CSS');l.eq('select-text',select.first_selected_option.get_attribute('value'),'css');select.select_by_value('js');l.eq('select-value',select.first_selected_option.text,'JavaScript');select.select_by_index(0);l.eq('select-index',select.first_selected_option.text,'HTML5');multi=Select(d.find_element(By.ID,'topics'));multi.select_by_value('html');multi.select_by_value('css');l.eq('multi-selected',len(multi.all_selected_options),2);multi.deselect_all();l.eq('multi-deselected',multi.all_selected_options,[]);l.err('Select-needs-native-tag',UnexpectedTagNameException,lambda:Select(d.find_element(By.ID,'results')));click(d,'button');l.eq('real-button-click',d.find_element(By.ID,'clicked').text,'1')
if __name__ == "__main__":
run('selenium-ele-operator')