[Wtr-general] Having trouble capturing text in java alert
Hi everyone, I'm having difficulty in capturing the text from a java alert, and would appreciate anyones input. Using AutoIT, for the pop up window works a treat, allowing me to capture the text, and then select the OK button to proceed with the script: require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' class TC_recorded < Test::Unit::TestCase def check_for_popups autoit = WIN32OLE.new('AutoItX3.Control') loop do sleep(3) ret = autoit.WinWait('Security Information', '', 1) text = autoit.WinGetText('Security Information', '') if (ret==1) puts text else puts "where is it?" end if (ret==1) then autoit.Send('{Yes}') end sleep(2) end end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("http://hmvdigital.co.uk/HMV.Digital.OnlineStore.Portal/Pages/Home.aspx";) @IE0.link(:text, "Sign in").click @popup = Thread.new { check_for_popups } # start popup handler @IE0.link(:href, "https://hmvdigital.co.uk/HMV.Digital.OnlineStore.Portal/Pages/HelpPopup.aspx?category=Managing_your_account&link=AboutRememberMe";).click Thread.kill(@popup) # end popup handler @IE0.close end end Unfortunately I have been unable to use AutoIt in dealing with an alerts, and have been using winClicker. I am able to select the OK button to proceed, but unable to capture any text: require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def startClicker( button , waitTime = 3) w = WinClicker.new longName = @IE0.dir.gsub("/" , "\\" ) shortName = w.getShortFileName(longName) c = "start ruby #{shortName }\\watir\\clickJSDialog.rb #{button } #{waitTime} " puts "Starting #{c}" w.winsystem(c) w=nil end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click startClicker("OK" , 3) @IE0.image(:alt, "continue").click @IE0.close end end As previously mentioned, any help would be greatly appreciated, many thanks ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
w = WinClicker.new text = w.get_static_text('Microsoft Internet Explorer') # returns an array for each static control text.each {|t| puts t} -Charley On 5/9/07, gary <[EMAIL PROTECTED]> wrote: Hi everyone, I'm having difficulty in capturing the text from a java alert, and would appreciate anyones input. Using AutoIT, for the pop up window works a treat, allowing me to capture the text, and then select the OK button to proceed with the script: require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' class TC_recorded < Test::Unit::TestCase def check_for_popups autoit = WIN32OLE.new('AutoItX3.Control') loop do sleep(3) ret = autoit.WinWait('Security Information', '', 1) text = autoit.WinGetText('Security Information', '') if (ret==1) puts text else puts "where is it?" end if (ret==1) then autoit.Send('{Yes}') end sleep(2) end end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto(" http://hmvdigital.co.uk/HMV.Digital.OnlineStore.Portal/Pages/Home.aspx";) @IE0.link(:text, "Sign in").click @popup = Thread.new { check_for_popups } # start popup handler @IE0.link(:href, " https://hmvdigital.co.uk/HMV.Digital.OnlineStore.Portal/Pages/HelpPopup.aspx?category=Managing_your_account&link=AboutRememberMe ").click Thread.kill(@popup) # end popup handler @IE0.close end end Unfortunately I have been unable to use AutoIt in dealing with an alerts, and have been using winClicker. I am able to select the OK button to proceed, but unable to capture any text: require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def startClicker( button , waitTime = 3) w = WinClicker.new longName = @IE0.dir.gsub("/" , "\\" ) shortName = w.getShortFileName(longName) c = "start ruby #{shortName }\\watir\\clickJSDialog.rb #{button } #{waitTime} " puts "Starting #{c}" w.winsystem(c) w=nil end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click startClicker("OK" , 3) @IE0.image(:alt, "continue").click @IE0.close end end As previously mentioned, any help would be greatly appreciated, many thanks ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
Thanks for the prompt reply. I added the code but it appears to return a value of 'Google', any ideas? require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def startClicker( button , waitTime = 3) w = WinClicker.new longName = @IE0.dir.gsub("/" , "\\" ) shortName = w.getShortFileName(longName) c = "start ruby #{shortName }\\watir\\clickJSDialog.rb #{button } #{waitTime} " puts "Starting #{c}" w.winsystem(c) w=nil end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click w = WinClicker.new text = w.get_static_text('Windows Internet Explorer') # returns an array for each static control text.each {|t| puts t} startClicker("OK" , 3) @IE0.image(:alt, "continue").click @IE0.close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
hi u can use this code.. def start_jsalert_clicker Thread.new{ system("ruby \"c:\\PSC\\jscriptExtraAlert.rb\"") } #please specify ur path of jscriptExtraAlert end u have to change ur windowhelper.rb file as... def push_alert_button @autoit.WinWait "Window Internet Explorer", "" text = @autoit.WinGetText "Window Internet Explorer" file = File.open("c:\\test.txt", "w") file.puts text puts text.to_s file.close @autoit.Send "{ENTER}" end after then u can read content of these file..ok... Regards Shalini Gupta On 5/9/07, gary <[EMAIL PROTECTED]> wrote: Thanks for the prompt reply. I added the code but it appears to return a value of 'Google', any ideas? require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def startClicker( button , waitTime = 3) w = WinClicker.new longName = @IE0.dir.gsub("/" , "\\" ) shortName = w.getShortFileName(longName) c = "start ruby #{shortName }\\watir\\clickJSDialog.rb #{button } #{waitTime} " puts "Starting #{c}" w.winsystem(c) w=nil end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click w = WinClicker.new text = w.get_static_text('Windows Internet Explorer') # returns an array for each static control text.each {|t| puts t} startClicker("OK" , 3) @IE0.image(:alt, "continue").click @IE0.close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
once again..use this function start_jsalert_clicker...before the object who is responsible for java alert popup.. On 5/10/07, SHALINI GUPTA <[EMAIL PROTECTED]> wrote: hi u can use this code.. def start_jsalert_clicker Thread.new{ system("ruby \"c:\\PSC\\jscriptExtraAlert.rb\"") } #please specify ur path of jscriptExtraAlert end u have to change ur windowhelper.rb file as... def push_alert_button @autoit.WinWait "Window Internet Explorer", "" text = @ autoit.WinGetText "Window Internet Explorer" file = File.open("c:\\test.txt", "w") file.puts text puts text.to_s file.close @autoit.Send "{ENTER}" end after then u can read content of these file..ok... Regards Shalini Gupta On 5/9/07, gary <[EMAIL PROTECTED]> wrote: > > Thanks for the prompt reply. > > I added the code but it appears to return a value of 'Google', any > ideas? > > require 'watir' # the controller > include Watir > require 'watir/WindowHelper' > require 'test/unit' > require 'test/unit/ui/console/testrunner' > require 'dl/win32' > require 'watir/winClicker' > > class TC_recorded < Test::Unit::TestCase > > def startClicker( button , waitTime = 3) > w = WinClicker.new > longName = @IE0.dir.gsub("/" , "\\" ) > shortName = w.getShortFileName(longName) > c = "start ruby #{shortName }\\watir\\clickJSDialog.rb #{button } > #{waitTime} " > puts "Starting #{c}" > w.winsystem(c) > w=nil > end > > def test_1 > @IE0 = IE.new > @IE0.set_fast_speed > @IE0.goto("www.hmv.co.uk") > @IE0.link(:text, "Sign In").click > > w = WinClicker.new > text = w.get_static_text('Windows Internet Explorer') # returns an > array for each static control > text.each {|t| puts t} > > startClicker("OK" , 3) > @IE0.image(:alt, "continue").click > > > @IE0.close > end > end > ___ > Wtr-general mailing list > Wtr-general@rubyforge.org > http://rubyforge.org/mailman/listinfo/wtr-general > ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
Hi still no luck I'm afraid, this is the closest I can get to what I want but with odd behaviour. For some reason the first alert does not appear to be recognised, but if I select this manually and then select the continue button again then the script kicks in again, extracts the text, puts the text out to the console, and then closes the alert as per the script. I'm just struggling to understand why it's not recognised the first time round. Any ideas? See script below: require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def captureText autoit = WIN32OLE.new('AutoItX3.Control') ret = autoit.WinWait "Windows Internet Explorer", "" text = autoit.WinGetText "Windows Internet Explorer", "" puts text.to_s autoit.Send "{enter}" end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click @IE0.image(:alt, "continue").click captureText @IE0.close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
hi, Tell me is 'continue' is responsible for popup... if yes..then how it will take text..u didnot define any function for popup hadling...include this function too.. def start_jsalert_clicker Thread.new{ system("ruby \"c:\\PSC\\jscriptExtraAlert.rb\"") }### please take care of this path...this path belongs to jscriptExtraAlert file according to my machine..u specify this as yours... end @IE0.link(:text, "Sign In").click start_jsalert_clicker @IE0.image(:alt, "continue").click captureText i mean call this function 'start_jsalert_clicker' before that object who is responsible for popup.. tell me if its helps u or not Regards and Thanks Shalini Gupta and use this as.. On 5/10/07, gary <[EMAIL PROTECTED]> wrote: Hi still no luck I'm afraid, this is the closest I can get to what I want but with odd behaviour. For some reason the first alert does not appear to be recognised, but if I select this manually and then select the continue button again then the script kicks in again, extracts the text, puts the text out to the console, and then closes the alert as per the script. I'm just struggling to understand why it's not recognised the first time round. Any ideas? See script below: require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def captureText autoit = WIN32OLE.new('AutoItX3.Control') ret = autoit.WinWait "Windows Internet Explorer", "" text = autoit.WinGetText "Windows Internet Explorer", "" puts text.to_s autoit.Send "{enter}" end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click @IE0.image(:alt, "continue").click captureText @IE0.close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
Thanks again for your help. i am getting the following load error - ubygems.8gemswatir-1.5.1.1164unittestsjscriptExtraAlert.rb (LoadError) require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def start_jsalert_clicker Thread.new{ system("ruby \"C:\\ruby\lib\ruby\gems\1.8\gems\watir-1.5.1.1164\unittests\jscriptExtraAlert.rb\"") } end def captureText autoit = WIN32OLE.new('AutoItX3.Control') ret = autoit.WinWait "Windows Internet Explorer", "" text = autoit.WinGetText "Windows Internet Explorer", "" puts text.to_s autoit.Send "{ENTER}" end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click start_jsalert_clicker @IE0.image(:alt, "continue").click captureText @IE0.close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
Hi, Make sure you escape '\' character in the file name by putting another '\' character in front of it. - Angrez On 5/11/07, gary <[EMAIL PROTECTED]> wrote: Thanks again for your help. i am getting the following load error - ubygems.8gemswatir- 1.5.1.1164unittestsjscriptExtraAlert.rb (LoadError) require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def start_jsalert_clicker Thread.new{ system("ruby \"C:\\ruby\lib\ruby\gems\1.8\gems\watir- 1.5.1.1164\unittests\jscriptExtraAlert.rb\"") } end def captureText autoit = WIN32OLE.new('AutoItX3.Control') ret = autoit.WinWait "Windows Internet Explorer", "" text = autoit.WinGetText "Windows Internet Explorer", "" puts text.to_s autoit.Send "{ENTER}" end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click start_jsalert_clicker @IE0.image(:alt, "continue").click captureText @IE0.close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
Great thanks. That's got rid of the error message, but it still appears to be running through twice and therefore stopping midway through. The 'sign in' click takes you through to sign in page. Th continue button should cause the alert to appear. I then need to capture the text within the popup. Then select ok to deal with alert. Then finally close IE. What appears to be happening is The 'sign in' click takes you through to sign in page. Th continue button should cause the alert to appear. the jsalert_clicker selects the ok to deal with the alert I need to manually select the continue button again which causes the alert to appear again the capureText extracts the text (text = autoit.WinGetText "Windows Internet Explorer", "") and also deals with the alert (autoit.Send "{ENTER}"). require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def start_jsalert_clicker Thread.new{ system("ruby \"C:\\ruby\\lib\\ruby\\gems\\1.8\\gems\\watir-1.5.1.1164\\unittests\\jscriptExtraAlert.rb\"") } end def captureText autoit = WIN32OLE.new('AutoItX3.Control') ret = autoit.WinWait "Windows Internet Explorer", "" text = autoit.WinGetText "Windows Internet Explorer", "" puts text.to_s autoit.Send "{ENTER}" end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click start_jsalert_clicker @IE0.image(:alt, "continue").click captureText @IE0. close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
Any more ideas anyone, surely I'm not the only one with this problem? ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
OK, now here's the latest update. Once again any help would be greatly appreciated as I'm having difficulty in extracting the text from an alert. Coming from a qa background rather than developer, I feel like a fish out of watir. Anyway, I've figured out how to deal with the script halting part way through but now I am no longer getting the text in the alert but a '1' instead: require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def captureText autoit = WIN32OLE.new('AutoItX3.Control') ret = autoit.WinWait "Windows Internet Explorer", "", 1 text = autoit.WinGetText "Windows Internet Explorer" puts text.to_s autoit.Send "{ENTER}" end def start_jsalert_clicker Thread.new{ system("ruby \"C:\\ruby\\lib\\ruby\\gems\\1.8\\gems\\watir-1.5.1.1164\\unittests\\jscriptExtraAlert.rb\"") } end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click start_jsalert_clicker @IE0.image(:alt, "continue").click captureText @IE0. close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
Hi Gary, Since you are starting a new thread for handling pop up. The text that you are sending to console will not be available to you. Also the captureText that you are writing won't be able to help you because the pop up will already be closed by start_js_clicker. If you look at the file 'jscriptextralert.rb' which you are calling in thread in function start_js_clicker, it creates new instance of WindowHelper class and then call function push_alert_button. Now in file 'watir/windowhelper.rb' go to function push_alert_button function, in that function you write the functionality to capture the text. In that function you can open a file, write the text of pop up to that file. Now instead of calling 'captureText', open the file and read text from that file. Hope this helps. You can go through following threads for more information. http://rubyforge.org/pipermail/wtr-general/2007-April/010466.html http://rubyforge.org/pipermail/wtr-general/2007-April/010512.html http://rubyforge.org/pipermail/wtr-general/2007-April/010523.html - Angrez On 5/15/07, gary <[EMAIL PROTECTED]> wrote: OK, now here's the latest update. Once again any help would be greatly appreciated as I'm having difficulty in extracting the text from an alert. Coming from a qa background rather than developer, I feel like a fish out of watir. Anyway, I've figured out how to deal with the script halting part way through but now I am no longer getting the text in the alert but a '1' instead: require 'watir' # the controller include Watir require 'watir/WindowHelper' require 'test/unit' require 'test/unit/ui/console/testrunner' require 'dl/win32' require 'watir/winClicker' class TC_recorded < Test::Unit::TestCase def captureText autoit = WIN32OLE.new('AutoItX3.Control') ret = autoit.WinWait "Windows Internet Explorer", "", 1 text = autoit.WinGetText "Windows Internet Explorer" puts text.to_s autoit.Send "{ENTER}" end def start_jsalert_clicker Thread.new{ system("ruby \"C:\\ruby\\lib\\ruby\\gems\\1.8\\gems\\watir- 1.5.1.1164\\unittests\\jscriptExtraAlert.rb\"") } end def test_1 @IE0 = IE.new @IE0.set_fast_speed @IE0.goto("www.hmv.co.uk") @IE0.link(:text, "Sign In").click start_jsalert_clicker @IE0.image(:alt, "continue").click captureText @IE0. close end end ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] Having trouble capturing text in java alert
Fantastic, works a treat. If we were down the pub I'd buy you a drink. Thanks. Gary ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general