#coding=utf-8 from selenium import webdriver import time import random driver = webdriver.Chrome() driver.get('url') driver.find_element_by_name('tb_uname').send_keys('username') driver.find_element_by_name('tb_pwd').send_keys('password') driver.find_element_by_name('tb_code').send_keys('') time.sleep(10) driver.find_element_by_name('btnSave').click() driver.find_element_by_link_text('xxxx').click() driver.find_element_by_link_text('yyyy').click() length = len(driver.find_element_by_xpath("//div[@id='list']").find_elements_by_link_text('编辑')) for i in range(0,length): l = random.randint(1,9) editions = driver.find_element_by_xpath("//div[@id='list']").find_elements_by_link_text('编辑') edit = editions[i] edit.click() driver.find_element_by_id('txtnewstype3').click() driver.find_element_by_xpath('//ul[@id="typeoption3"]/li[%d]'%l).click() time.sleep(1) driver.find_element_by_id('ckhead').click() time.sleep(1) driver.find_element_by_id('ckpush').click() time.sleep(1) driver.find_element_by_id('btnsave').click() time.sleep(1) driver.switch_to_alert().accept() driver.back() time.sleep(1) driver.find_element_by_xpath("//div[@id='list']").find_element_by_link_text('删除').click() |