[WinError 10053] 你的主机中的软件中止了一个已建立的连接。
用python写了一段自动化脚本,在循环的时候报ConnectionAbortedError: 你的主机中的软件中止了一个已建立的连接。错误,第一次执行没有问题,就是不能循环,求个大神解答下,代码如下:from selenium import webdriver
from selenium.webdriver.support.ui import Select
#import shenpiliu
import time
import bs4
import csv
import re
import xlrd
# xpath路径
file = 'C:\\Users\Administrator\Desktop\\2.xlsx'
data = xlrd.open_workbook(file)
table = data.sheets()
i = 1
for p in range(table.nrows-1):
Driver = webdriver.Chrome()
import GeneralMethod
GM = GeneralMethod
x = 0
HT_data = table.row_values(i)
xpathName = '//*[@class="form-control"]'
xpathPwd = '//*[@type="password"]'
xpathid = "W2BtnLogin"
url1 = "http://60.12.232.90:8002/##_TAB"
url2 = "http://60.12.232.90:8004/workflow/task?TaskId=S0629137fcf5c6b93b6298338f25a8c&ProcessName=%E5%90%88%E5%90%8C%E5%AE%A1%E6%89%B9%E5%8D%95&ProcessVersion=1&FetchDraft=1"
user = "00019974"
HTDLeiXuanZe = '//div[@id="ConnectInfo"]//tr/td//span[@class="l-btn-left"]' # 合同大类选择
HTZLeiXuanZe = '//div[@id="ConnectInfo"]//tr/td//span[@class="l-btn-left"]' # 合同中类选择
HTXLeiXuanZe = '//div[@id="ConnectInfo"]//tr/td//span[@class="l-btn-left"]' # 合同小类选择
frame1 = "ifSYS_FORM"
HTMChengID = "_easyui_textbox_input9"
HT_Start_dateID = "_easyui_textbox_input36"
HT__End_dateID = "_easyui_textbox_input37"
HTKS_Xuanze = '//span/../div/span/span'
HTKSdate = '//div[@class="panel combo-p"]/div//tr//a'
HTJS_Xuanze = '//span/../div/span/span'
HTJSdate = '/html/body/div/div/div/table/tbody/tr/td/a'
HT_JinE_ID = "_easyui_textbox_input25"
WFMC_xpath = '//span/..//span'
# 数据维护
HTDL = "收"
HTZL = "销售合同"
HTXL = "销售合同"
HTMC = "加盟合同1"
HTJE = 100000
fujian = 'C:\\Users\Administrator\Desktop\\1.docx'
DengLu = GM.Log_in(HT_data,url1,url2)
time.sleep(2)
GM.iframe_qiehuan_id('ifSYS_FORM')
GM.xuanze_click(HTDLeiXuanZe,HT_data,1)
GM.xuanze_click(HTZLeiXuanZe,HT_data,2)
GM.xuanze_click(HTXLeiXuanZe,HT_data,2)
GM.alert() # alert弹出框处理
GM.ID_text(HTMChengID,HT_data)
GM.Date_XuanZe(HTKS_Xuanze,HTKSdate)
GM.Date_XuanZe(HTJS_Xuanze,HTJSdate)
GM.ID_text(HT_JinE_ID,str(HT_data))
GM.xuanze_click(WFMC_xpath,'',1)
GM.xuanze_click('//*[@id="CompanyDetailInfo"]/table/tbody/tr/td/div/div/span/a/span/span','',2)
GM.ID_text('_easyui_textbox_input38',HT_data)
GM.ID_text('_easyui_textbox_input40',HT_data)
GM.ID_text('_easyui_textbox_input41',HT_data)
GM.ID_text('_easyui_textbox_input20',HT_data)
GM.ID_text('_easyui_textbox_input39',str(HT_data))
GM.ID_text('_easyui_textbox_input22',str(HT_data))
GM.ID_text('_easyui_textbox_input23',str(HT_data))
GM.DianJi('//*[@id="nnfegRentPaymentDetail-toolbar"]/a/span/span')
GM.xuanze_click('//*[@id="divDetails1"]/tbody/tr/td/div/div/span/a/span/span',HT_data,1)
GM.Date_XuanZe('//*[@id="divDetails1"]/tbody/tr/td/div/div/span/span/a','/html/body/div/div/div/table/tbody/tr/td/a')
GM.Date_XuanZe('//*[@id="divDetails1"]/tbody/tr/td/div/div/span/span/a','/html/body/div/div/div/table/tbody/tr/td/a')
GM.Date_XuanZe('//*[@id="divDetails1"]/tbody/tr/td/div/div/span/span/a','/html/body/div/div/div/table/tbody/tr/td/a')
GM.ID_text('_easyui_textbox_input26',str(HT_data))
GM.ID_text('_easyui_textbox_input27',str(HT_data))
GM.ID_text('_easyui_textbox_input28',str(HT_data))
GM.DianJi('//*[@id="nnfegRentPaymentDetail-dialog-buttons"]/a/span/span')
GM.xpath_text('//*[@id="ctl00_ContentPlaceHolder1_realContactFile"]//input',fujian)
GM.xpath_text('//*[@id="ctl00_ContentPlaceHolder1_realIDCardFiles"]/div/div/a//input','C:\\Users\Administrator\Desktop\\QQ截图20180627142856.png')
GM.xpath_text('//*[@id="ctl00_ContentPlaceHolder1_realLicenseFile"]//input','C:\\Users\Administrator\Desktop\\QQ截图20180627142856.png')
GM.xpath_text('//*[@id="ctl00_ContentPlaceHolder1_realTrusteeFile"]//input','C:\\Users\Administrator\Desktop\\QQ截图20180627142856.png')
GM.xpath_text('//*[@id="ctl00_ContentPlaceHolder1_realPropertyFile"]//input','C:\\Users\Administrator\Desktop\\QQ截图20180627142856.png')
GM.SQR_TiJiao("")
time.sleep(3)
user1 = GM.RWQD()
GM.To_quit()
time.sleep(30)
continue
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoAlertPresentException
import time
import bs4
import csv
import re
Driver = webdriver.Chrome()
def is_element_exist(xpath1): # 判断xpath是否存在
s1 = Driver.find_elements_by_xpath(xpath1)
if len(s1) == 0:
return False
else:
return True
def Log_in(username,url,url2):#用户登录
Driver.get(url)
Driver.find_element_by_xpath( '//*[@class="form-control"]').send_keys(username)
Driver.find_element_by_xpath('//*[@type="password"]').send_keys("1")
Driver.find_element_by_id("W2BtnLogin").click()
if url2 !="":
Driver.get(url2)
def iframe_qiehuan_id(frame):
Driver.switch_to.frame(frame)
def iframe_qiehuan_tga(x):
frame = Driver.find_elements_by_tag_name('iframe')
Driver.switch_to.frame(frame)
def xuanze_click(xpath1,text1,x):
xuanze = Driver.find_element_by_xpath(xpath1)
xuanze.click()
iframe_qiehuan_tga(x)
time.sleep(3)
if text1 != "":
if is_element_exist('//span[@class="textbox easyui-fluid"]/input[@id="_easyui_textbox_input1"]'):
Driver.find_element_by_xpath('//span[@class="textbox easyui-fluid"]/input[@id="_easyui_textbox_input1"]').send_keys(text1)
elif is_element_exist('//span[@class="textbox easyui-fluid"]//input[@id="_easyui_textbox_input2"]'):
Driver.find_element_by_xpath('//span[@class="textbox easyui-fluid"]//input[@id="_easyui_textbox_input2"]').send_keys(text1)
elif is_element_exist('//*[@id="SearchName"]/..//input[@id="_easyui_textbox_input1"]'):
Driver.find_element_by_xpath('//*[@id="SearchName"]/..//input[@id="_easyui_textbox_input1"]').send_keys(text1)
if is_element_exist('//*[@id="form1"]/div/div/div/span/a/span/span'):
Driver.find_element_by_xpath('//*[@id="form1"]/div/div/div/span/a/span/span').click()
time.sleep(2)
Driver.find_element_by_xpath('//*[@id="form1"]/div/div/div/div/div/div/div/div/table//tr').click()
if is_element_exist('//*[@id="form1"]/div/span/a/span'):
Driver.find_element_by_xpath('//*[@id="form1"]/div/span/a/span').click()
time.sleep(2)
Driver.find_element_by_xpath('//*[@id="form1"]/div/div/div/div/div/table/tbody/tr').click()
if is_element_exist('//*[@id="form1"]/div/span/span/a'):
Driver.find_element_by_xpath('//*[@id="form1"]/div/span/span/a').click()
time.sleep(2)
Driver.find_element_by_xpath('//*[@id="FYLXTree"]/li/div').click()
if is_element_exist('//div[@class="panel datagrid easyui-fluid"]//div[@class="datagrid-view2"]//tr[@id]'):
Driver.find_element_by_xpath('//div[@class="panel datagrid easyui-fluid"]//div[@class="datagrid-view2"]//tr[@id]').click()
Driver.switch_to_default_content()
iframe_qiehuan_id('ifSYS_FORM')
Driver.find_element_by_xpath('/html/body/div/div/a/span/span').click()
def ID_text(id,text):
Driver.find_element_by_id(id).send_keys(text)
def Date_XuanZe(xpath1,xpath2):
Driver.find_element_by_xpath(xpath1).click()
Driver.find_element_by_xpath(xpath2).click()
def alert():
try:
alert=Driver.switch_to_alert()
'''添加等待时间'''
time.sleep(2)
'''获取警告对话框的内容'''
print (alert.text)#打印警告对话框内容
alert.accept() #alert对话框属于警告对话框,我们只能接受弹窗
'''添加等待时间'''
time.sleep(2)
except NoAlertPresentException:
print('没有alert弹出框')
def DianJi(xpath):
Driver.find_element_by_xpath(xpath).click()
def xpath_text(xpath,text):
Driver.find_element_by_xpath(xpath).send_keys(text)
def SQR_TiJiao(value):
Driver.switch_to_default_content()
Driver.find_element_by_xpath('/html/body/div/div/div/a/span').click()
Driver.switch_to.frame("ifSYS_FORM")
if value !="":
Driver.find_element_by_xpath('//*[@id="nnf-send-confirm"]/table/tbody/tr/td/div/div/span/textarea').send_keys(value)
else:
if is_element_exist('//*[@id="nnf-send-confirm"]/table/tbody/tr/td/div/div/span/input[@value=""]'):
Driver.find_element_by_xpath('//*[@id="nnf-send-confirm"]/table/tbody/tr/td/div/div/span/input[@value=""]').send_keys('摘要未自动生成')
Driver.find_element_by_xpath('//*[@id="nnf-send-confirm-buttons"]/a').click()
def RWQD():
time.sleep(3)
Driver.find_element_by_xpath('//ol[@class="breadcrumb taskviewnavi"]/li/a').click()
Driver.switch_to.frame('ifSYS_TASKLIST')
time.sleep(2)
if is_element_exist("//span/../../../td/span"):
SPRen = Driver.find_element_by_xpath("//span/../../../td/span").text
if len(SPRen)<9:
username1 = 'sa'
else:
username1 = str(SPRen)[-9:-1]
return username1
else:
return 0
Driver.switch_to_default_content()
def To_quit():
Driver.quit()
def SPR_TiJiao(username,url):
Driver = webdriver.Chrome()
Driver.get(url)
Driver.find_element_by_xpath( '//*[@class="form-control"]').send_keys(username)
Driver.find_element_by_xpath('//*[@type="password"]').send_keys("1")
Driver.find_element_by_id("W2BtnLogin").click()
time.sleep(5)
Driver.switch_to.frame("if")# 定位到首页iframe
time.sleep(2)
DJLCheng = Driver.find_element_by_xpath('//tr[@class="read ng-scope"]/td//span') # 点击流程
DJLCheng.click()
time.sleep(3)
Driver.switch_to_window(Driver.window_handles)# 获取新页面
time.sleep(3)
Driver.find_element_by_xpath('//div[@class="mail-body text-right tooltip-demo ng-scope"]/a').click()# 提交
dialog_box = Driver.switch_to_alert()
time.sleep(1)
dialog_box.accept()# 点击确定
time.sleep(5)
我也遇到类似问题,你后来是怎么解决的??
我的问题是,driver = webdriver.Firefox(), driver.get(file) 这两个函数跟 find_element_by_class_name在用一个函数内就能正常使用。 但是将driver作为参数传递调用函数就不行。总是报错:
ConnectionAbortedError: 你的主机中的软件中止了一个已建立的连接。
页:
[1]