Selenium_python实例代码(3)
2013-08-28 14:48
417 查看
#-*- coding:utf-8 -*-
from selenium import webdriver
import time
import os
dr=webdriver.Chrome()
file_path = 'file:///'+os.path.abspath('checkbox.html')
dr.get(file_path)
#选择所有的checkbox并勾选上
for i in range(1,4):
checkbox=dr.find_element_by_css_selector('input[id=c%d]'%i)
checkbox.click()
time.sleep(2)
#把页面上最后一个checkbox的勾去掉
dr.find_elements_by_css_selector('input[type=checkbox]').pop().click()
time.sleep(2)
dr.quit()
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
For instance, conside this page source:
The form elements can be located like this:
from selenium import webdriver
import time
import os
dr=webdriver.Chrome()
file_path = 'file:///'+os.path.abspath('checkbox.html')
dr.get(file_path)
#选择所有的checkbox并勾选上
for i in range(1,4):
checkbox=dr.find_element_by_css_selector('input[id=c%d]'%i)
checkbox.click()
time.sleep(2)
#把页面上最后一个checkbox的勾去掉
dr.find_elements_by_css_selector('input[type=checkbox]').pop().click()
time.sleep(2)
dr.quit()
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
For instance, conside this page source:
<html> <body> <form id="loginForm"> <input name="username" type="text" /> <input name="password" type="password" /> <input name="continue" type="submit" value="Login" /> <input name="continue" type="button" value="Clear" /> </form> </body> <html>
The form elements can be located like this:
login_form = driver.find_element_by_xpath("/html/body/form[1]") login_form = driver.find_element_by_xpath("//form[1]") login_form = driver.find_element_by_xpath("//form[@id='loginForm']")
相关文章推荐
- Python 中的Selenium异常处理实例代码
- Selenium_Python实例代码(2)
- Selenium_python 实例代码(1)
- Selenium_python实例代码(3)
- Selenium_Python实例代码(2)
- Python selenium抓取微博内容的示例代码
- python的Crypto模块实现AES加密实例代码
- Python os.SEEK_SETs 代码实例
- Python操作Mysql实例代码
- python导出chrome书签到markdown文件的实例代码
- selenium-python-unittest自动化测试框架(数据和代码完全分离)
- 用python实现的线程池实例代码
- Python时间戳与时间字符串互相转换实例代码
- python+selenium简单实现拖动元素实例
- [Python]利用soaplib访问webservice的实例代码
- 使用Python进行QQ批量登录的实例代码
- Python模拟登陆淘宝并统计淘宝消费情况的代码实例分享
- python中集合类型创建、更新、删除、修改以及操作符使用实例代码
- python通过elixir包操作mysql数据库实例代码
- python将ansible配置转为json格式实例代码