def upload_file_other(self, locator, file_path, flag=False, is_sleep=True):
"""文件上传 - 非 input 类型"""
self.driver._is_remote = False
ele = self.find_element(locator)
self.highLightElement(ele)
if flag:
webdriver.ActionChains(self.driver).move_to_element(ele).perform()
self.driver.execute_script("arguments[0].click();", ele)
else:
webdriver.ActionChains(self.driver).move_to_element(ele).click(ele).perform()
t.md_logger().info(f"点击元素:{locator}")
file_path = util.file_path(file_path)
common.upload_file(file_path)
t.md_logger().info(f"选择本地文件:{file_path}")
if is_sleep:
time.sleep(1)

def upload_file_gui(self, locator, file_path):
self.driver._is_remote = False
ele = self.find_element(locator)
webdriver.ActionChains(self.driver).move_to_element(ele).click(ele).perform()
time.sleep(2)
file_path = util.file_path(file_path)
pyautogui.write(file_path)
time.sleep(2)
pyautogui.press('enter')
time.sleep(2)
pyautogui.press('enter')

def upload_file_autoit(self, locator, file_paths):
ele = self.find_element(locator)
webdriver.ActionChains(self.driver).move_to_element(ele).click(ele).perform()
time.sleep(2)
file_paths = util.file_path(file_paths)
file_path = util.file_path_upload()
try:
if os.path.exists(file_path):
os.system('%s %s' % (file_path, file_paths))
except Exception as e:
raise e

这个是采用的三种方式,均能在 Selenium Hub 上传成功,node 节点运行时,对于非 input 框文件上传操作无效


↙↙↙阅读原文可查看相关链接,并与作者交流