如何在python中使用selenium webdriver上传文件
这是我尝试过的以下脚本,此处脚本已通过,但文件未上载:如何在python中使用selenium webdriver上传文件,python,selenium,selenium-webdriver,webdriver,python-unittest,Python,Selenium,Selenium Webdriver,Webdriver,Python Unittest,这是我尝试过的以下脚本,此处脚本已通过,但文件未上载: import unittest from selenium import webdriver import time import os from selenium.webdriver.common.keys import Keys from selenium .webdriver.common.action_chains import ActionChains class notaryfileupload(unittest.TestCa
import unittest
from selenium import webdriver
import time
import os
from selenium.webdriver.common.keys import Keys
from selenium .webdriver.common.action_chains import ActionChains
class notaryfileupload(unittest.TestCase):
def setUp(self):
self.driver=webdriver.Chrome()
def test_Notaryfileupload(self):
driver=self.driver
driver.get("https://mtsdev.westus.cloudapp.azure.com/#")
time.sleep(30)
username=driver.find_element_by_xpath("//*[@id='login-form-username']")
username.send_keys("vamsi@mindtechsol.com")
driver.implicitly_wait(4)
password=driver.find_element_by_xpath("//*[@id='login-form-password']")
password.send_keys("Mindtech@2017")
driver.implicitly_wait(4)
submit=driver.find_element_by_xpath("//*[@id='login-form-submit']")
submit.click()
driver.implicitly_wait(8)
driver.maximize_window()
time.sleep(5)
searchbox=driver.find_element_by_xpath("//*[@id='content']/div/div[2]/div[1]/div[1]/div/div/input")
searchbox.send_keys("BN0000023")
time.sleep(15)
click=driver.find_element_by_xpath("//*[@id='content']/div/div[2]/table/tbody/tr[1]/td[1]/span")
click.click()
time.sleep(20)
driver.refresh()
time.sleep(20)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(6)
driver.execute_script("window.scrollBy(0, -550);")
time.sleep(6)
attachment=driver.find_element_by_xpath("//*[@id='content']/data-ng-form/div/div[2]/div[8]/div/work-area-template/div/div[2]/div[2]/table/thead/tr[2]/th/div/div/input[2]")
# driver.execute_script('arguments[0].style = ""; arguments[0].style.display = "block"; arguments[0].style.visibility = "visible";', attachment)
attachment.send_keys("C:\Users\vignesh\Desktop\New folder\comments.txt")
time.sleep(30)
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
#attachment=driver.find_element_by_name("multifile-939[]")
#attachment.send_keys("C:\Users\vigne\Desktop\important pyton\dental.txt")
用相关的HTMLHi Debanjan更新问题:我在上传文件附件=驱动程序时遇到了以下几行中的问题。通过xpath(“/*[@id='content']/data ng form/div/div[2]/div[8]/div/work area template/div/div[2]/table/thead/tr[2]/th/div/div/div/div/input[2]”查找元素。发送密钥(“C:\Users\vignesh\Desktop\New folder\comments\comments.txt”)在这里,脚本被传递,但文件并没有被上传,而是一条注释。使用此信息更新主要问题