Short version: new tabs in Chrome prevent old tabs from being used, fixing that means that opened tabs with PDFs in them get reused before a human can examine the PDFs.
Long version:
Originally it worked like this:
open new Chrome window to main page of the app (tab #1)
2.[do process A and then] click the button and a new tab (tab #2) opens with PDF A in it.
Go back to tab #1 [do process B and then] click the button and a new tab (tab #3) opens with PDF B in it.
Go back to tab #1 [do process C and then] click the button and a new tab (tab #4) opens and Word document C document gets downloaded.
Go back to tab #1 [do process D and then] click the button and a new tab (tab #5) opens and Word document D document gets downloaded.
All tabs stay open and PDFs can be viewed. Not perfect, but workable.
But then things changed. I pulled frequently used stuff out, put them in methods in another file so all of the various tests could use them, which seemed like a good idea. But that seems to have caused problems with losing focus on the original window. (I may be wrong) now I'm stuck with:
open new Chrome window to main page of the app (tab #1)
[do process A and then] click the button and a new tab (tab #2) opens with PDF A in it.
Stay in tab #2 [do process B and then] click the button and a new tab (tab #3) opens with PDF B in it. PDF A is now lost
Stay in tab #3 [do process C and then] click the button and a new tab (tab #4) opens and Word document C document gets downloaded. PDF B is now lost
Stay in tab #4 [do process D and then] click the button and a new tab (tab #5) opens and Word document D document gets downloaded.
This was caused by using "b.windows.last.use"
So I tried using "b.windows.first.use"
But that fails, because focus isn't going back to tab #1, and watir can't find the object in the modal that it needs to click.
(in `assert_ok': Element is not clickable at point (737.5, -373) (Selenium::WebDriver::Error::UnknownError))
So far as I can tell, I would be fine if I could do any one of the following
get PDFs to download. I cannot. This page seemed promising, but the code didn't work and I couldn't fix it.
get watir to go back to the first page, "for realsies", and find the buttons it needs
perhaps open a new tab for every section of the test (I'm going to look into this one, but I'm not overly hopeful)
Any ideas?
I updated Watir and Ruby both within the last two months. I'm using Chrome on OSX. Moving to Windows or IE are not viable options.
Here is a section of the code. No, I'm not a programmer first and foremost.
Thanks.
currenturl = "stackoverflow.placeholder.com/works"
# print Inventory Report .PDF (document 1)
b.goto currenturl
b.div(:id, 'page').a(:text, 'Inventory Report').click
sleep 1
b.div(:id, 'printInventoryReportModal').a(:text, 'A4').click
b.link(:id => "submitBTNprint-inventory-report").fire_event "onclick"
# print General List .PDF (document 2)
b.goto [main page URL]
b.div(:id, 'page').a(:text, 'General List').click
sleep 1
b.div(:id, 'printGeneralInventoryListModal').a(:text, 'A4').click
b.link(:id => "submitBTNprint-general-list").fire_event "onclick"
# print General List .DOC (document 3)
b.goto [main page URL]
b.div(:id, 'page').a(:text, 'General List').click
sleep 1
b.div(:id, 'printGeneralInventoryListModal').a(:text, '.DOC').click
b.div(:id, 'printGeneralInventoryListModal').a(:text, 'A4').click
b.link(:id => "submitBTNprint-general-list").fire_event "onclick"
It seems mostly that the browser.window function is not working the way you expect, or you are not using it properly. Since your question currently contains very little in terms of examples of how you are trying to change windows (tabs) it's very difficult to tell what you might be doing wrong.
To start with I would use IRB to do some exploring and troubleshooting
Get into IRB, then use
require 'watir-webdriver'
b = Watir::Browser.new :chrome
Now manually navigate the browser window that opens and get it into the state where you have multiple tabs open
Now try something like this in IRB to see if you can get it to spit out window titles
b.windows.each {|window| puts window.title}
If the titles are different, then you should be able to use that to set which window you want to use. If they are not different you will need to look at other attributes to see if there is an easy way to identify which window you want. (or maybe just use :index)
Try below code,
sleep (2)
#browser.driver.switch_to.window(#browser.driver.window_handles[put_your_index])
#browser.window(:title,"Please put your title here").use do
end
#browser.button.when_present.click
when you want to want to switch back to your actual window, use the
same code as above and change the window index accordingly.
For an example, if parent window index is 0 and then child window index would be 1
Related
Suppose I have a link to Google of the form
Google
There are a couple different ways to open this link in a new tab:
Left click on the link
Right click on the link and select Open Link in New Tab
I've noticed on an app I work on that there is different behavior between #1 and #2. For example, when I console out window.opener for #1 I get an object like
wheres #2 gives me undefined.
What are the differences between these two ways to open the link? I can't find any information about how a browser (in my case, Chrome), might handle these cases.
I had the same problem, two different behaviors were happening in those two cases in an application I was working on. I had to search everywhere to see why, only to find your question that helped me identify the problem.
in case #1, of course when you left click the link, the user is giving the developer the choice of whither to open in a new tab. whereas in case #2, the user is making the choice instead.
case #1 is like doing window.open(URL, '_blank');
case #2 is like opening a new tab and manually typing the URL;
the only thing I found is that when you open the URL with target blank (case #1), that new tab or window will link to the parent (opener) by window.opener until you close that window, the opener will be back to null
as far as behavior, the source code of the new URL may include logic on window.opener you may need to search if this was the case. I don't see why the browser would treat them differently, it has to be from the source code.
I have an application where you can display 2 kind of content.
There are 3 "main content" pages, which have the urls:
/ (root)
/favorites
/timeline
There is also a settings popup. It goes on top of the "main content". I should be able to deep-link to this setting popup directly. Opening that link directly (like, from an email) should lead to the content displayed for the root / in the background with the settings popup opened in the foreground.
When the settings popup gets closed, it should not affect main content that was under the popup. Url should take back its previous value (the one of the main content: one of / /favorites or /timeline)
Usecase: being somewhere, opening the settings popup, and then closing it.
Be on /favorites
Click on /settings link
Settings popup should open
Click on close button in settings popup
Settings popup should close and url should be /favorites
I'm having trouble implementing this. I've tried to use history.goBack() but it is actually not what I want. On close I don't want to go back, but I actually want to push a new /favorites entry into the history.
Also, using goBack means that if the user comes directly from link /settings, then there's nowhere to go back because there's no back history entry...
I'm also trying to see how I could use history.push() but it seems a bit unnatural to me (and very tightly coupled!) that my settings popup could have to do something like history.push("/favorites") to close itself...
Any idea on how to solve this problem in an idiomatic way?
The question is opposite to this one.
Say I open link in a new tab. Currently it is opened, but not loaded. It starts loading only when I select it. I want so that I open a lot of links on a page and those tabs start loading without need to be selected.
Furthermore, there is another problem. When I open link, select that tab, tab is loaded. Then I go to another tab, do something there and return to the first tab. So this tab starts to reload again.
How to fix this?
My version of Chrome is - 48.0.2564.116. It starts to happen recently.
If you are using (in settings) "continue where you left off" then switch to "Open specific page or set of pages" try it there, then switch back
The answer is https://superuser.com/questions/1048029/disable-auto-refresh-tabs-in-chrome-desktop#answer-1049471. Shorter, the flag #automatic-tab-discarding needs to be disabled on chrome://flags.
I want to give my users the option of opening a tab into its own window rather than merely switching the current window’s display to that tab. I have lots of tabs in my app, and the user often wants to study a few of those over long periods of time. For example, the user may watch charts being updated over time via Push.
Currently I add an "Open Window" button to a tab's layout. This opens a new browser window with the current tab’s layout.
Is there any other way to do this? A context-menu on the tab itself? User holding down a keyboard modifier (Control key, Command key, Option/Alt key) while clicking the tab?
Actually, there is one trick:
tabSheet.setCloseHandler((tabsheet, tabContent) -> {/** make new window **/});
Of course it works if tabSheet is closeable.
So if anybody click close button then you could do your own logic - in this example open new window.
But it could be misleading. To handle this problem you could replace close caption from x to any other more meaningful sign.
For example, look at Valo TabSheet demo. If you look in HTML code, than you notice something like this:
<span class="v-tabsheet-caption-close" aria-hidden="true" aria-disabled="true">×</span>
I think you are able to change this x using for example JavaScript.
When I run my project in Netbeans 6.8, it loves to open the index page automatically. It's annoying because I always keep a tab with the page I'm working on when I work, so I don't need this index page. It also makes my current page lose focus.
I have tried not specifying an index or my project URL, but then I can't run or save my project.
How can I prevent it from doing so?
In NetBeans 7.4:
Right-click your project, select 'Properties'
In left hand pane of popup, select 'Run Configuration'
In the right pane of the popup, in the bottom right corner of the list of fields, click 'Advanced...'
Select radio button 'Do Not Open Web Browser'
I ran into that issue as well. The solution is quite simple - go to the menu bar:
Run/Run File.
That's it. It will just run the current php script without going to the index.php.
Basically, you want to reopen the same page (refresh it ?) in the browser ? You can set settings in the project properties > run configuration, then chaange the index file or project url. But apart from that I am afraid that you can't do anything to prevent opening a new window on run. When you click 'run', netbeans says to your OS : "Hey, let's open that page (your_project_URL/index_file) now". The OS thinks and execute a command like "default_browser url", where the argument "url" is here your_project_URL/index_file. Then the browser thinks it's a new page to open, and BAM, opens a new page.
Just use shift+F6 which will open the current page with focus.