Selenium:从文件系统拖放到webdriver?我必须测试一个包含拖放区域的Web应用程序,用于从本地文件系统上传文件。我的测试环境是基于C#的。对于自动化测试,我使用了Selenium,但我无法从文件系统中拖动文件。上传区域是一个div标签(没有input标签)。那么最好的方法是什么?AutoIt(可以放入网络浏览器)?西库里?单独使用Selenium是可能的,但这并不简单。它需要在页面中注入一个新的INPUT元素以通过SendKeys接收文件。然后脚本需要通过向目标区域发送dragenter、dragover、drop事件来模拟drop。staticvoidMain(string[]args){vardriver=newChromeDriver();driver.Url="https://react-dropzone.js.org/";IWebElementdroparea=driver.FindElementByCssSelector("[data-preview='Basicexample'][style]");DropFile(droparea,@"C:UsersflorentDesktopcapture.png");驱动程序退出();}conststringJS_DROP_FILE="for(varb=arguments[0],k=arguments[1],l=arguments[2],c=b.ownerDocument,m=0;;){vare=b.getBoundingClientRect(),g=e.left+(k||e.width/2),h=e.top+(l||e.height/2),f=c.elementFromPoint(g,h);if(f&&b.contains(f))break;if(1来源:https://gist.github.com/florentbr/349b1ab024ca9f3de56e6bf8af2ac69e之前的答案是正确的,并且与Chrome驱动程序完美配合,但MozillaGecko驱动程序可能存在问题,抛出org.openqa.selenium.ElementNotVisibleException为了避免这种情况,请删除input.style.display='none';你可以使用input.style.opacity=0;如果你需要让它消失。以上就是C#学习教程:Selenium:draganddropfromthefilesystemtowebdriver?如果分享的所有内容对您有用,需要了解更多C#学习教程,希望您多多关注---本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
