def cacule_xy(num):
alpha = 21 #利用selenium的location方法获得图片的坐标,计算相邻文字的中心距离
all_alpha = [] #需要点击的文字的距离列表
first = int(num[0]) #获取第一个点
all_alpha.append(int(num[0])*21)
for x in num[1:]:
all_alpha.append((int(x)-first)*alpha) #步长是在原先的坐标点基础上增加
first = int(x) #-》[155,100]->[176,100]
return all_alpha
begin_loc = browser.find_element_by_css_selector('.Captcha-chineseImg').location
begin_y = begin_loc['y']+21
#time.sleep(3000)
dict_xy = input("请输入需要点击的顺序字符串")
xy_set = cacule_xy(dict_xy)
for j in xy_set:
ActionChains(browser).move_by_offset(begin_loc['x']+j, begin_y).click().perform()
begin_y = 0
browser.find_element_by_css_selector('.Button.SignFlow-submitButton').click()
ActionChains用于模拟鼠标点击,参数为浏览器驱动(selenium),单击后鼠标会停留,所以需要在上一次点击的坐标上计算