一.文件上传
1.文件上传(input)1.1.当页面标签为input时,使用send_keys向其输入一个文件地址来实现上传''' selenium只支持input元素的上传,直接使用send_keys将文件绝对地址写入元素即可 '''importtimefromseleniumimportwebdriver withwebdriver.Chrome()asdirver:dirver.get('http://www.baidu.com')dirver.find_element_by_xpath('//span[@class="soutu-btn"]').click()time.sleep(2)input=dirver.find_element_by_xpath('//input[@class="upload-pic"]')input.send_keys(r'C:\Users\Administrator\Desktop\123.png')time.sleep(5)2.文件上传(pywinauto)2.1.很多时候页面不是使用input来进行文件上传,则需要使用第三方包来操作系统界面2.2.pywinauto优点:只能在windows使用 缺点:能选择多个文件,可使用中文路径2.3.安装pip install pywinauto2.4.使用importtime fromseleniumimportwebdriverfrompywinauto.keyboardimportsend_keys withwebdriver.Chrome()asdriver:driver.get('http://www.baidu.com')span=driver.find_element_by_xpath('//span[@class="soutu-btn"]')span.click()time.sleep(1)# 打开选择文件窗口select_span=driver.find_element_by_class_name('upload-wrap')select_span.click()time.sleep(2)# 选择文件send_keys(r'C:\Users\Administrator\Desktop\123.png')time.sleep(1)&nb学习地址:https://blog.csdn.net/m0_65657661/article/details/129682947