bootstrap form表单提交_[Selenium]28. 处理表单元素
生活随笔
收集整理的這篇文章主要介紹了
bootstrap form表单提交_[Selenium]28. 处理表单元素
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
場(chǎng)景
表單對(duì)象的操作比較簡(jiǎn)單,只需要記住下面幾點(diǎn)
- 使用send_keys方法往多行文本框和單行文本框賦值;
- 使用click方法選擇checkbox
- 使用click方法選擇radio
- 使用click方法點(diǎn)擊button
- 使用click方法選擇option,從而達(dá)到選中select下拉框中某個(gè)具體菜單項(xiàng)的效果
代碼
form.html
<!DOCTYPE html> <html><head><meta http-equiv="content-type" content="text/html;charset=utf-8" /><title>form</title> <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.5.0/jquery.js"></script><link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet" /> <script type="text/javascript">$(document).ready(function(){$('input[type=submit]').click(function(){alert('selenium webdriver is better than watir-webdriver');});});</script></head><body><h3>form</h3><div class="row-fluid"><div class="span6 well"> <form><fieldset><legend>Legend</legend> <label class="checkbox"><input type="checkbox"> Check me out</label><label class="radio"><input type="radio"> select me </label><label class="select"><select><option>0</option><option>1</option><option>2</option></select> select one item</label><input type="submit" class="btn" value="submit" /></fieldset></form></div></div></body><script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script></html>form.py
from selenium import webdriver from time import sleep import osdr = webdriver.Chrome() file_path = 'file:///' + os.path.abspath('./html/form.html') dr.get(file_path)# 選中checkbox dr.find_element_by_css_selector('input[type=checkbox]').click() sleep(1)# 選中radio dr.find_element_by_css_selector('input[type=radio]').click() sleep(1)# 選擇下拉菜單中的最后一項(xiàng) dr.find_element_by_tag_name('select').find_elements_by_tag_name('option')[-1].click() sleep(1)# 點(diǎn)擊提交按鈕 dr.find_element_by_css_selector('input[type=submit]').click() sleep(1)alert = dr.switch_to.alert print(alert.text) alert.accept()dr.quit()【重要消息】
感謝知友您能夠看到這部分內(nèi)容,本文是軟件測(cè)試系列知識(shí)中selenium自動(dòng)化測(cè)試工具的一篇,筆者認(rèn)為本部分全面的知識(shí)應(yīng)該包含如下圖所示的內(nèi)容:
如果知友對(duì)這部分內(nèi)容感興趣,可以持續(xù)關(guān)注小編的賬號(hào),除此之外,小編還錄制了不少這方面的技術(shù)視頻,知友如果有需要,可以私聊本小編獲取哦!
總結(jié)
以上是生活随笔為你收集整理的bootstrap form表单提交_[Selenium]28. 处理表单元素的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: viwer连接不到服务器 vnc_vnc
- 下一篇: 小程序数据框有重影_微信小程序云开发数据