Ah, this got lost in the business that is Watir General this week If you are using the block it will automatically switch back to the original window for you. I don't like using blocks for things like this, so I explicitly switch back using `#original_window`.
Neither approach automatically closes a window, so if it isn't the side effect of another action, you'll need to do that explicitly. On Tuesday, August 7, 2018 at 11:00:40 AM UTC-7, rajagopalan madasami wrote: > > Hi here you forgot to reply my previous mail. When I use block when > switching to the window , it's automatically needs to close the window, eh? > Please see my previous mail as well. > > On Tue 7 Aug, 2018, 8:56 PM Titus Fortner, <[email protected] > <javascript:>> wrote: > >> Oh no, I gave the right code: >> https://stackoverflow.com/a/51666596/4072371 >> >> Also, original_window is stored for you, you don't need to create it. >> >> b.select_list(id: 'selWeek').options.each do |option| >> option.select >> b.button(id: 'csbtnSearch').click(:control) >> b.windows.last.use >> p b.element(xpath: '//*[@id="form1"]/table/tbody/tr[1]/td[1]/a').text >> b.window.close >> b.original_window.use >> end >> On Tue, Aug 7, 2018 at 8:20 AM Titus Fortner <[email protected] >> <javascript:>> wrote: >> > >> > Gah, I mixed in Selenium code. >> > >> > In Selenium `driver.close` closes the window, and `driver.quit` ends >> > the session. >> > In Watir it needs to be `b.window.close` >> > >> > Let me find the SO entry to fix it. >> > On Tue, Aug 7, 2018 at 4:05 AM <[email protected] <javascript:>> >> wrote: >> > > >> > > Hi Titus, >> > > >> > > We have recently had the talk in Stackoverflow, where you have >> suggested me this code >> > > >> > > I tried using your code but when I reach b.close, it's closing the >> browser totally not the tab which has opened recently so I couldn't connect >> to the original window. >> > > >> > > Please execute this code >> > > >> > >> require 'watir' >> > >> driver = Selenium::WebDriver.for :chrome >> > >> b = Watir::Browser.new driver >> > >> >> > >> b.goto ' >> https://services.wiltshire.gov.uk/PlanningGIS/LLPG/WeeklyList' >> > >> >> > >> b.select_list(id: 'selWeek').options.each do |option| >> > >> option.select >> > >> b.button(id: 'csbtnSearch').click(:control) >> > >> original = b.original_window >> > >> b.windows.last.use >> > >> p b.element(xpath: '//*[@id="form1"]/table/tbody/tr[1]/td[1]/a').text >> > >> b.close >> > >> b.original_window = original >> > >> end >> > > >> > > >> > > >> > > browser b.close is closing the browser not the newly opened tab so I >> couldn't connect to the original window and this throws the error. Is it a >> bug? >> > > >> > > -- >> > > -- >> > > Before posting, please read >> https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group >> . >> > > In short: search before you ask, be nice. >> > > >> > > [email protected] <javascript:> >> > > http://groups.google.com/group/watir-general >> > > [email protected] <javascript:> >> > > --- >> > > You received this message because you are subscribed to the Google >> Groups "Watir General" group. >> > > To unsubscribe from this group and stop receiving emails from it, >> send an email to [email protected] <javascript:>. >> > > For more options, visit https://groups.google.com/d/optout. >> >> -- >> -- >> Before posting, please read >> https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. >> >> >> In short: search before you ask, be nice. >> >> [email protected] <javascript:> >> http://groups.google.com/group/watir-general >> [email protected] <javascript:> >> --- >> You received this message because you are subscribed to the Google Groups >> "Watir General" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- -- Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected] --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
