senlenium send.key批量输入

#coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.get("http://192.168.1.17:8090/login") time.sleep(3) driver.find_element_by_id("amount").send_keys("输入你的账号") driver.find_element_by_id("password").send_keys("输入你的密码") driver.find_element_by_xpath("/html/body/section/div/div[2]/div/form/input").click() time.sleep(5) a= 0 while a<=3:     connect = ["test1","hi",u"地方","dhf"]     for i in connect:         driver.find_element_by_xpath("/html/body/header/div/div[1]/ul/li[3]").click()         time.sleep(5)         driver.find_element_by_class_name("add-shop").click()         time.sleep(3)        …

selenium 获取登录cookie

#coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.get("http://192.168.1.17:8090/login") time.sleep(3) driver.find_element_by_id("amount").send_keys("173") driver.find_element_by_id("password").send_keys("123") driver.find_element_by_xpath("/html/body/section/div/div[2]/div/form/input").click() time.sleep(5) cookie = driver.get_cookies() cookie_list = [] for i in cookie:     cookie = i[’name’] + ‘=’ + i[’value’]     cookie_list.append(cookie) cookie_str = ";".join(cookie_list) print cookie_str driver.quit()

selenium 登录Demo

#coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.get(“http://192.168.1.17:8090/login”) time.sleep(3) driver.find_element_by_id(“amount”).send_keys(“173”) driver.find_element_by_id(“password”).send_keys(“123”) driver.find_element_by_xpath(“/html/body/section/div/div[2]/div/form/input”).click() time.sleep(4) driver.quit()

selenium web页面滚动滚动条

#coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.set_page_load_timeout(10) driver.get(‘https://www.baidu.com/’) driver.maximize_window() driver.find_element_by_id(“kw”).send_keys(“selenium”) driver.find_element_by_id(“su”).click() time.sleep(3) js = “var c=document.body.scrollTop=100000” driver.execute_script(js) time.sleep(6) driver.quit() 第二种: #coding=utf-8 from selenium import webdriver import time driver = webdriver.Safari() driver.set_page_load_timeout(10) driver.get(‘https://www.baidu.com/’) driver.maximize_window() driver.find_element_by_id(“kw”).send_keys(“selenium”) driver.find_element_by_id(“su”).click() time.sleep(3) driver.execute_script(“window.scrollTo(0,100000)”) time.sleep(6) driver.quit()

selenium 网页搜索Demo

#coding=utf-8 from selenium import webdriver from selenium.webdriver.common.keys import Keys import unittest class PythonSearch(unittest.TestCase): def setUp(self): self.driver = webdriver.Safari() def test_search(self): driver = self.driver driver.get(“http://www.python.org”) elem = driver.find_element_by_name(“q”) elem.send_keys(“pyhton”) elem.send_keys(Keys.RETURN) assert “No results found.” not in driver.page_source def tearDown(self): self.driver.quit() if __name__ == “__main__”: unittest.main()

selenium+python2.7 +chrome环境搭建

window 安装步骤: 1、下载python安装。 https://www.python.org/downloads 根据自己的操作系统,选择相应的版本进行安装。我的安装目录为:C:\Python27 2、配置python环境变量。 修改我的电脑–>属性–>环境变量–>系统变量中的PATH。变量值: ;C:\Python27;C:\Python27\Scripts; 3、安装selenium 我是通过pip安装的,命令为:pip install selenium 当然也可以直接下载selenium包进行安装。步骤为:cmd进入目录执行python setup.py install 4、安装chromedriver 下载与chrome对应版本的chromedriver。将chromedriver文件放在chrome安装目录下并配置到环境变量中。配置方法参考步骤2. 附:chrome与chromedriver版本之间的对应关系。 所有版本的chromedriver可以在http://chromedriver.storage.googleapis.com/index.html中进行下载。 至此:python+chromedriver 在window中配置已经结束