ruby – 使用watir-webdriver选择本地文件
发布时间:2020-12-17 02:54:50 所属栏目:百科 来源:网络整理
导读:我正在尝试使用watir-webdriver自动化从html页面中选择本地文件的过程 我有以下HTML bodyform method="post" action="upload" enctype="multipart/form-data"test file to upload: input type="file" name="file" size="60" id="test"/input type="submit" v
我正在尝试使用watir-webdriver自动化从html页面中选择本地文件的过程
我有以下HTML <body> <form method="post" action="upload" enctype="multipart/form-data"> test file to upload: <input type="file" name="file" size="60" id="test"/> <input type="submit" value="Upload" name="upload" id="upload" /> </form> </body> 我正在尝试单击id为test的输入,并使用watir-webdriver设置我希望上传的本地文件的路径. 我可以使用以下单击按钮以显示选择窗口 @browser.goto 'http://www.test.com' @browser.button(:id => 'test').click 但是,我试图使用以下(从研究,这似乎是正确的方法.虽然不工作) @browser.file_field(:name => 'file').set("C:pathtotestfilevalidTest.xml") 这会导致以下错误 Watir::Exception::UnknownObjectException: unable to locate element,using {:name=>"file",:tag_name=>"input",:type=>"file"} 试 @browser.button(:id => 'test').set("C:pathtotestfilevalidTest.xml") 导致以下错误 NoMethodError: undefined method `set' for #<Watir::Button:0x3859920> 有人可以帮忙吗?我很难理解为什么file_field选项不起作用. 解决方法
尝试使用以下功能:
@browser.file_field(:id,"upload").set("filepath") 此外,如果您使用的是IE浏览器,请确保您使用的是IEDriverServer_Win32_2.33.0,因为它在此驱动程序上运行正常而不是最新的驱动程序. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |