有没有一种方法可以实现使用Selenium上传Magento图像的拖放操作?

Uma*_*745 6 drag-and-drop magento python-3.x selenium-webdriver

我正在尝试使用python和selenium在magento上自动执行产品上传,但是我在上传图像时遇到了问题。

我试图用 id="fileupload"

driver.find_element_by_id("fileupload").send_keys('C:\\Users\\PC\\Desktop\\Code\\magento-bot\\image1.png')  
Run Code Online (Sandbox Code Playgroud)

这似乎可行,因为当我将鼠标指针放在上传区域时,文件名会显示出来,但是提交后没有图像。

我也尝试单击上传区域,然后通过执行以下操作选择要上传的文件:

uploadElement = driver.find_element_by_xpath('//html/body/div[2]/main/div[2]/div/div/div/div[2]/div[5]/div[2]/fieldset/div/div[2]/div[1]/div[1]/div[1]')
uploadElement.click()
driver.switch_to.active_element().send_keys(os.getcwd()+"\image1.png)
Run Code Online (Sandbox Code Playgroud)

但我最终遇到此错误'FirefoxWebElement' object is not callable 最后,我尝试像这样模拟拖放:

element = os.getcwd()+"\image1.png"
target = bot.find_element_by_id('fileupload')
ActionChains(bot).drag_and_drop(element, target).perform
Run Code Online (Sandbox Code Playgroud)

但我得到下面的错误

AttributeError("move_to requires a WebElement")

拖放图像

任何帮助将不胜感激。

Uma*_*745 2

我的问题的临时解决方案是 AutoIt。

非常感谢@KunduK如何使用 python selenium 上传带有角度组件的图像

我定位了图像上传区域的 xpath,然后 autoit 使用下面的代码完成了剩下的工作:

autoit.win_wait_active("File Upload",5)
if autoit.win_exists("File Upload"):
   autoit.control_send("File Upload","Edit1",filepath+"{ENTER}")```
Run Code Online (Sandbox Code Playgroud)