How to handle new tab opening with Splash? - scrapy-splash

I'm scraping website which has a very annoying link (<a> HTML tag) - it opens the small pop-up form on click and after submitting it, opens new browser tab (and switches focus to it) with URL that I need, and also redirects old tab to another page.
Successful submitting of the pop-up form was easy, but I don't know how to get URL of this new tab.
And as the documentation says, Splash can work only with one tab, so is it impossible to do that?

As Splash's developer comments on this GitHub issue this feature is not implemented.
But I posted my solution to this problem on the same issue.
Example:
function main(splash, args)
assert(splash:go(args.url)) -- execute JS code below only after loading the page
splash:runjs("var newTabURL")
splash:runjs("newTabURL = null") -- sometimes JS can't find variable without this line
splash:runjs("window.open = function(url){newTabURL = url}")
-- actions which open the new tab
local new_tab_url = splash:evaljs("newTabURL")
-- other actions
end

Related

When writing end to end selenium tests, should I navigate to a page or just open the URL?

Say I need to submit a form on the 'Classes' page. I am testing the 'enroll into class' feature. Do I navigate to the page by clicking on the menu bar, or do I just directly open the URL of the page?
It depends on the scenario you need to test.
As an autoimation engineer you need to work according to the documentation.
If no scenario defined you can choose easiest way to do that.
Incase clicking on the menu bar is the part of your #Test, you have to access the base page and navigate to the desired page by invoking click() on the menu bar.
Else you can directly open the URL of the page.

CRM 2013 WebResource IFrame

I have an HTML web resource in an opportunity that produces a css tab control containing all children opportunity to the current record.
I do this through Ajax and javascript and everything works fine, a new tab is made for each child and it shows an opportunity record inside; the only issue is that it will only show the current record inside of this tab - effectively creating an endless loop.
If I paste the URL from the IFrame into the browser it shows the proper record using the right form that I specify(one that doesn't contain another web resource).
Does anyone know why it wouldn't show the same form as it navigates to? If I try google.com it works, just not for this URL:
http://server/CRM/main.aspx?etn=opportunity&pagetype=entityrecord&navbar=off&id=%7B"+val.OpportunityId+"%7D&extraqs=formid%3DC1EC704C-D29B-4786-806F-195D0A80CF07%0D%0A#255409204
Try constructing the URL with this format:
http://server/CRM/main.aspx?etc=3&extraqs=formid%3dC1EC704C-D29B-4786-806F-195Dā€Œā€‹0A80CF07%7d&id=%7b<EnterOppIdHere>%7d&pagetype=entityrecord
Use the Entity Type Code (etc parameter) instead of the Name (etn) and note that everything after that should be part of the extraqs parameter.

Does selenium / webdriver with protractor wait for async activity in a describe block before continuing?

I have code in a desribe block but some of my set up code is outside of the block. That's the code that sets up elements.
When my code executes it runs fine but then I see the browser go to another page before parts of my test have completed. With a different page on the browser then it looks for elements and throws an exception when they are not there.
So how can I handle this problem of the browser going to another page before tests are completed?
As per my understanding of the question you want to be on the same page and don't want to move to the new page which loads when you click on to a link/button. If this is the case then to be on the same page you cane use.
Use this command -String oldwindow=window.getWindowHandle();
window.switchTo().window(oldwindow);
Use this command just below the button code which throws a new window. I am a java programer thats why the code written is in java.
getWindowHandle Methods stores the url of current window in oldwindow string and by using window.switchTo().window(oldwindow) it won't move to new window because you are passing oldwindow as argument for the command.
For more go through the Webdriver documentation by clicking this link

Durandal - Distinguishing entry from a 'back' button vs. navigate()

In my Durandal app, I have a search page - I'd like to:
Load a clean search page when it's loaded from the menu (router.navigate('#/search'))
When navigating to an item from the search page, then using the back button, this should return to the original search result & criteria.
I'm also storing my search criteria & results as a (app-wide) singleton, which is injected to the view model via RequireJS.
Am I able to: distinguish how the user entered the page? I can see that the activate() lifecycle call is triggered under both entry methods.
If you want to know if the user landed to the search page by clicking a link/button from your app or by visiting by entering a url/back button, what I would do is to raise an event when the user clicks on the link/button and on the search page check if the event has been raised or pass some parameter in router.navigate.
I have been recently doing some work on distinguishing a user click from within the application and a back or forward button from the browser. If you are using router.navigate() to navigate around the Durandal application the router.explicitNavigation flag is set to true. But you would want to capture this before the 'router:navigation:complete' event in 'router:route:activating' event as the flag gets set back to false on 'router:navigation:complete' event.
Bottom line is if you are using router.navigate to navigate around the application the router.explicitNavigation property will be set to true and if navigation is triggered using the back/forward button in the browser router.explicitNavigation will be set to false.
In actual case you might not even need to perform router.navigate() to distinguish between an in app navigation and a browser back/forward because Durandal's router module listens to all 'a' tag click on the document level and sets the explicitNavigation flag to true. However I haven't tested this fully.

Gecko:Login to website

I am new to web browser control geckoFx. I want to login to a webpage using it. So how can i do it in vb.net
I tried navigating to the webpage using navigate method.
InitializeComponent()
Xpcom.Initialize("D:\xulrunner")
myBrowser = New GeckoWebBrowser()
myBrowser.Parent = Me
myBrowser.Dock = DockStyle.Fill
myBrowser.Navigate("www.google.com")
But how can i login to website?
I tried searching for few examples of using gecko.But i didn't get. So where i can get examples related to using gecko?
There are a number of different ways to do this. After you have navigate to the page and it has finished loading:
execute some javascript to fill in the fields and click the submit button.
C# javascript execute examples
use C# (or vb.net) to get the required DOM fields, modify them with the required values, then get the DOM submit button and call the click api.
Examples of GetElementById
GeckoInputElement class that has a click method