在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一般的图片上传能用send_keys("图片路径")解决 但是遇到flash类型的图片上传,send_keys()就无奈了,这时候我们可以引用第三方工具autoit来进行操作 这边提供一个实例 #encoding:utf-8 require 'selenium-webdriver' require 'test/unit' require 'rubygems' require 'win32ole' class OpentestCase<Test::Unit::TestCase def setup @dr = Selenium::WebDriver.for :chrome @url ="http://bbs.opentest.cn" @dr.get @url sleep 1 end def test_should_enter_into_post_page_successfully @dr.find_element(:xpath,"//*[@id='category_63']/table/tbody/tr[1]/td[2]/h2/a").click sleep 1 @dr.find_element(:id,'newspecial').click @dr.find_element(:id,'subject').send_keys("tim post a message") @dr.find_element(:id,'e_attach').click @dr.find_element(:id,'SWFUpload_1').click at = WIN32OLE.new('AutoItX3.Control') #等待窗口出现 at.WinWait("选择要上载的文件,通过:bbs.opentest.cn", "", 2) #等待窗口激活 at.WinActivate("选择要上载的文件,通过:bbs.opentest.cn") sleep 2 #设置控件文本 at.ControlFocus( "选择要上载的文件,通过: bbs.opentest.cn", "", "[CLASS:Edit; INSTANCE:1]" ) at.Send("D:\\image\\1.jpg") sleep 2 #模拟键盘alt+o at.Send("!O") sleep 2 @dr.find_element(:id,'attach_confirms').click @dr.switch_to.frame('e_iframe') @dr.find_element(:xpath,"//body").send_keys("tim post a message") @dr.switch_to.default_content @dr.find_element(:id,'postsubmit').click end def test_postpage_title_correctly title = @dr.find_element(:id,'thread_subject').text assert(title,"tim post a message") end def teardown @dr.close end end
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论