1.上传文件---不墨迹,直接上代码
for upload_file in upload_file_list:
# 选择文件
ActionChains(self.dr).move_to_element_with_offset(flash_obj, 50, 12).click().perform()
time.sleep(1)
EditControl(ClassName="Edit").SendKeys(upload_file)
# 一级窗口"#32770","打开"
# dialog = win32gui.FindWindow("#32770", "打开")
dialog = win32gui.FindWindow("#32770", "选择要上载的文件,通过: xxx.com")
# ComboBox = win32gui.FindWindowEx(dialog, 0, 'ComboBox', None)
# 编辑按钮
# edit = win32gui.FindWindowEx(dialog, 0, 'Edit', None)
# win32gui.SendMessage(edit, win32con.WM_SETTEXT, None, upload_file)
# 打开按钮打开(&O)
button = win32gui.FindWindowEx(dialog, 0, 'Button', "打开(&O)")
win32gui.SendMessage(dialog, win32con.WM_COMMAND, 1, button) # 点击打开按钮
time.sleep(1)
time.sleep(2)
# 上传文件
ActionChains(self.dr).move_to_element_with_offset(flash_obj, 130, 12).click().perform()
2. 网页对话框 --- showModalDailog模态对话框 (在网页上层显示的对话框,如果查看元素,无法定位):如下图
解决思路:首先不难发现这是一个 showModalDailog模态对话框 ,所以可以跳转到该句柄,然后获取源代码,根据html结果并找到xpath,解决定位问题,直接就可以点击了,代码如下
all_handles = self.dr.window_handles
# current_window = self.dr.current_window_handle
# for handle in all_handles:
# print(handle.title)
# if handle == current_window:
self.dr.switch_to_window(all_handles[-1])
time.sleep(2)
# 网页源码
page = driver.page_source
print(page)
# 流程处理-SOA -- 网页对话框
self.dr.find_element_by_xpath('//input[@value="取消"]').click()
print("对话框处理完毕!返回原句柄继续下一个")
# 关闭对话框之后,返回上一个句柄
self.dr.switch_to_window(all_handles[0])