access popup from browser extension - userscripts

I need to open a popup window and parse its contents.
I can do this from injected script as follows:
win = window.open(url);
$(win.document).find(...);
But this is blocked by popup blocker and user has to allow popups from the site.
If I do the same from the content script itself, then window is opened without being blocked, but win is undefined.
Is it possible at all to get contents of the popup window without being blocked by popup blocker?
Note that I open page from the same domain as the page the content script is called from.

You can use iframe or invisible iframe, if you don't want to show up iframe to users.
Append an iframe to document instead of opening a new window, then get contents of iframe.
$(function() {
$("#add").click(function() {
$("#temp").append('<iframe id="tempiframe"
src="http://fiddle.jshell.net/_display/"></iframe>');
$("#tempiframe").load(function() {
alert("hey I get this from iframe\n"
+$(this).contents().find("pre").html());
});
});
});​
Here is a jsFiddle DEMO

Related

How can I click on a popup window in selenium Java

I am new to selenium and try to automate (using selenium Webdriver in Java for Window and using Chrome Driver) an App (ABC Project) which contains a Registration Form.
After completing the form and click on Registration Button I get a popup info message (modal) with close (X) & OK Button & Headline in the message: Under ABC Project the following is displayed & Text which informs the user that the registration was successful.
I have tried several ways to click on OK button in this popup window but no success:
1.
Alert alert = driver.switchTo().alert();
alert.accept();
2.
driver.findElement(By.xpath("//input[#value = 'alert']")).click();
Alert javascriptAlert = myTestDriver.switchTo().alert();
System.out.println(javascriptAlert.getText()); // Get text on alert box
javascriptAlert.accept();
----> in this case I get only the text of the opened tab (from registration window: driver.getTitle();:ABC Project) but not the text of teh Info message(to see in logger.info)
3.
String winHandleBefore =
driver.getWindowHandle();
driver.findElement(By.xpath("//div[#class='col-md-4']/button[1]")).click();
// Xpath of register Button
Set handles = driver.getWindowHandles(); ..... --->>, In this case, I don't get any Window Handler of new window the window handler from old and new are the same
Additional Hint:
I am also not able to click anywhere else in Window to skip the popup window
In Google Developer tool I don't see also any source code and no Elements from the popup window (when the popups appear.
I heard from developer that this window is a javascript but I don't
see anything in source code too (it did not also work with solution b
above)
I appreciate for any tips and supports
Thanks
This picture posted looks like a javascript alert.
So the below code should have worked.
Alert alert = driver.switchTo().alert();
alert.accept();
Maybe it is a wait issue. Try WebDriverWait
Alert alert = new WebDriverWait(driver, 20).until(ExpectedConditions.alertIsPresent());
alert.accept();

Switch to other site from main application

In my current application, manually when i click on a Button say 'Buy' button it takes me to a different site within the same browser (in another tab).
Usually I can switch to the Tab using
driver.switchTo().defaultContent();
But while am doing it in automation the second site is opening in a different browser. How can i handle this. I want this to open within a the same browser like how its happening when i do it manually. Please help me out. Thanks in advance.
You don't define the programming language, but in Java it is as follows:
// Store the current window handle
String winHandleBefore = driver.getWindowHandle();
// Perform the click operation that opens new window
// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
// Perform the actions on new window
// Close the new window, if that window no more required
driver.close();
// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);
// Continue with original browser (first window)
Source: How to switch to the new browser window, which opens after click on the button?

Save Dialog box in Silverlight

i am working on Silverlight 5,
Application has functionality like save data in user's local pc as CSV. while developing functionality it's working perfect at our local PC. when we click on "Export" Button save file dialog box appear and save at selected location. but after deployed on our server save file dialog box will not appear on screen.
dialog = new SaveFileDialog();
dialog.DefaultFileName = "Exported Data";
dialog.Filter = string.Format("File Type (*{0}) | *{0}", (".csv"));
dialog.DefaultExt = string.Format("{0}", ("csv"));
//Show the dialog
bool? dialogResult = dialog.ShowDialog();
Make sure you call ShowDialog() method right after "Export" button click event, this is Silverlight security feature.
See: http://msdn.microsoft.com/en-au/library/system.windows.controls.savefiledialog(v=vs.95).aspx
You show a save dialog control using the ShowDialog method. For security purposes Silverlight file and print dialogs must be user-initiated. This means you must show them from a user-initiated action such as the click event handler for a button. In addition, there is a limit on the time allowed between when the user initiates the dialog and when the dialog is shown. If the time limit between these actions is exceeded, an exception will occur.

Why does an IE window pops up when closing a form on WebBrowser.DocumentCompleted handler

I have a form that has a WebBrowser control. Onload, it navigates to some URL.
On DocumentCompleted event handler, after getting the needed data the form is closed. This works most of the time, but sometime it pops up an IE window w/ the same URL after the form has already closed.
I noticed that in DebugView, it logs m_useSurfacePresenter 1. When this gets logged before the Close() is called, there is no popup. But when this gets logged after the Close() is called, then the popup appears.
You need to check the JavaScript .onunload event in that document, if it is set to open a new window (browser) when that page is unloading, then it will be triggered when you close your winform which is hosting the webbrowser control, and in turn, the page.
So, when you close the winform, the page's onUnload event in the webbrowser control will also be triggered as a result due to the way the events are chained in a Document/Page --> WB Control --> WinForms Form setup.
You can actually set this to nothing, by running a particular JS command directed to the page in the WB control, you can set the .OnUnload event to "function () {};", which will ensure whatever it is set to will be turned into Nothing/Null. Here is a code example:
window.onunload = function () { };
Let me know how it goes, and I will help you out if that doesn't fix it. Notice the above is JS, and there are ways to execute JS directly from teh WB Control, many examples on the web, there are actually 2 ways, one using .execScript and another one using the newer method, which is .InvokeScript.

How to Programatically "Click" a Silverlight HyperlinkButton (WebAii)

I'm currently using the WebAii automation framework to write some user interface tests against a Silverlight 3 application. I'm new to Silverlight and suspect that I'm missing some bit of information about the HyperlinkButton.
The application has a HyperlinkButton and I'm attempting to write code that navigates to the page, finds the button the page, then "clicks" that button (which will then navigate to the NavigateUri as specified in the HyperlinkButton's properties).
I can't figure out how to execute that click. The code I have thus far (simplified):
Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
ActiveBrowser.NavigateTo("http://server/appname/");
var slApp = ActiveBrowser.SilverlightApps()[0];
var menu = slApp.FindName<StackPanel>("LinksStackPanel");
var linkicareabout = menu.Find.ByName<HyperlinkButton>("Some Cases");
I'd expect to see some sort of Click() action, or Navigate() method that I could invoke on the "linkicareabout" variable, but I must be missing how it's done.
What you are looking for is the User object off the HyperlinkButton. All controls that WebAii comes with have that object. This way you can invoke any user action on any control type.
linkicareabout.User.Click()
The User object supports any user action you can think of and mimic real user interactions. Check out the documention here.
I was unable to do this myself and instead, had to write my own navigation code. For Firefox and IE, you can just use HtmlPage.Window.Navigate to navigate to the desired URL.
However, Safari and Chrome need some extra work. I had to use hidden HTML components and some javascript interops.
This workaround is detailed here.
Basically, it entails adding a hidden anchor and button to the HTML page containing your Silverlight control, and then modifying the anchor and clicking the button via calls to the DOM.
HtmlElement anchor = HtmlPage.Document.GetElementById("externalAnchor");
HtmlElement button = HtmlPage.Document.GetElementById("externalButton");
if ((anchor != null) && (button != null))
{
anchor.SetProperty("href", url);
button.Invoke("click", null);
}

Resources