I want to apply the keyboard shortcut Ctrl+W (closes a browser tab) on an asp.net button. When I click on the asp.net button, it should work like the above controls. Is it possible? And if it is, from where can I get the code for Ctrl+W(close a browser tab).
window.close() won't work to close a browser's tab.
Simply put: it won't work, because you cannot close the current page with JavaScript (well, you can do it from your own developer console, but not from a script). Please take a look at this question for details: window.close and self.close do not close the window in Chrome
Related
I have page where i have button which makes ajax-request to server and load simple modal form. I have one input and one button in form.
How i can test it on C# ?
I need just navigate to link -> click -> load form. Then just input text and click button.
I dont want use selenium for it.
Thx, it really only selenium. So i just need to use it.
Issue: My selenium script is not recognizing and closing a dialog box that pops up when I redirect to a URl that contains file to download. The attached image shows the dialog I am referring to.
I know this has been asked a million times and I have spent at least 24 hours researching and trying other suggestions posted across the web but with no success. I am hoping the attached image will clarify which Firefox dialog box I am referring too.
I have tried the following solutions
1. Creating IAlerts (Alert element is not found)
2. Searching by trying to find the element by xpath (xpath to cancel was not found)
3. WindowsHandler Method (was not able to figure out the window name)
Any help on this would be greatly appreciated. Thank You in advance!
FireFox Dialog
There are several types of "popups".
Javascript dialogs - These are NOT HTML dialogs but are instead Javascript created dialogs. These consist of alert(), confirm(), and prompt() and can be handled with Alert.
HTML dialogs - These take on various forms depending on how they are formatted. If you right-click on the dialog and see the typical context menu for your browser, then it's an HTML dialog. They are part of the DOM of the current page so you can use Selenium to access this just as you would any other page (e.g., no window handles needed).
Browser window - These are actually another browser window that pops up and may look like a dialog, depending on how it's formatted. It's different than an HTML dialog because it can be moved outside of the current browser page frame. You will need to use window handles to access these windows as you would another tab in the browser. Once you get ahold of the window handle, you can access the HTML of the page like any other page.
Browser dialog - these take on various forms but are akin to System dialogs. They are not made up of HTML so they cannot be accessed by Selenium. Other than using a library to access them, you can interact with them in a limited fashion by sending keys such as <SPACE>, <TAB>, <ENTER>, etc.
What you have pictured is a (4) browser dialog. They it takes on different forms depending on the browser you do the action on. Your best course of action is probably send keys. Sometimes, depending on the browser, you can specify settings to autodownload a file to a specific location so that the dialog doesn't come up. I've never used this so I can't direct you there.
I was able to find and close a download dialog box by checking the amount of open windows after the dialog appears. This solution worked for me.
Find a link to open a dialog and click it:
var link = MyBrowser.Driver.FindElement(OpenQA.Selenium.By.Id("Button"));
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("arguments[0].click();", link);
Get the new window count after the dialog opens:
var newWindowCount = MyBrowser.Driver.WindowHandles.Count;
Switch to the newly opened dialog and close it:
MyBrowser.Driver.SwitchTo().Window(MyBrowser.Driver.WindowHandles[newWindowCount-1]);
MyBrowser.Driver.Close();
The message reads:
To help protect your security, Windows Internet Explorer blocked this site from
downloading files to your computer. Click here for more options...
I am receiving this error when I try to initiate a download after successfully filling a CAPTCHA in my ASP.NET (C#) website.
Has anybody faced this issue earlier? If so can you please let me know how you have tried to make it work. I have no option to remove the AJAX calls in my code.
This issue seems to be specific to IE7. The work around suggested for this issue by Microsoft is:
To ensure that your Web site downloads are not blocked, do not automatically launch a file download. Instead, use hyperlinks or buttons that require a user action. If you use a script to navigate to the resource, it must run synchronously within the context of the OnClick event handler for the link.
I even tried to create a button dynamically and trigger a click after my AJAX call is completed. Even then the issue is not resolved.
Try this
To stop the information bar from blocking file and software downloads
Open Internet Explorer by clicking the Start button , and then clicking Internet Explorer.
Click the Tools button, and then click Internet Options.
Click the Security tab, and then click Custom level.
Do one or both of the following:
To turn off the Information bar for ActiveX controls, scroll to the ActiveX controls and plug-ins section of the list, and then, under Automatic prompting for ActiveX controls, click Enable.
To turn off the Information bar for file downloads, scroll to the Downloads section of the list, and then, under Automatic prompting for file downloads, click Enable.
Click OK, click Yes to confirm that you want to make the change, and then click OK again.
I have an ASP.NET WebForm.
When users click on a link, it calls another page. That page, in turn, references an assembly and initiates a download, which takes some time to appear as it is rendered on the fly.
The issue:
I want to display a popup message: "Please wait download initiated" when users click the download button. When the Internet Explorer download window appears, I want to disable the original popup.
AFAIK, Elad is true. But you can try one thing. If your are throwing content from page, then just before writing content do the stuffs you want
Is there TAB control and how to open page2 from button click ?
On asp.net ?
I work with C# and Visual Studio 2008 and ASP.NET
Thanks in advance
The standard ASP.NET controls that ship with the .NET Framework do not include a tab control. However you can find a number of implementations on the internet, I would suggest you look the jQuery UI.
As for the button click redirecting to page2 you can handle the button click event on the server side and use a Response.Redirect("page2.aspx") to redirect the users browser to the desired page. Other alternatives exist like using an anchor (link) which will request the second page directly.
Set the SelectedTab property to the index of the tab you want to display in the click event of your button.