After close the modal window, how to go back to the previus page?
I need to run a comand, but isn't identify my currente page.
You can use the following solution to go back to the previous page after closing the modal window (works with Coordinates, for example):
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
System.Threading.Thread.Sleep(5000);
js.ExecuteScript("window.scrollBy(0,950)");
Related
I'm accessing an SSO through an ASP/C# page and using the following code to open up a popup window:
string s = "window.open('" + getSSOlink(ah1.InstitutionUserID, cardnumber) + "','popup_window', 'width=980,height=600,resizable=yes');";
Page.ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
After opening the popup, I need to click 2 links deep into the the popup window navigate to a specific part of the page. The id on the first page is id25, and on the second page is cuRewardsLink, and it is the same every time the SSO opens. After the 2nd link is clicked, the user will be directed to a Rewards system.
I'm trying to find a way to open a new browser window that navigates automatically to the Rewards page. Ideally, they would not see the loading of the first two pages in the popup, just the final destination. The links within the popup do not have static URLs, there is an AJAX function returning information from the click(s) that create the link.
After the popup opens, I'm not sure how to access the HTML elements in the current browser window (the popup window). I tried using the WebBrowser class to navigate to the page, wait for loading,and click the links, but got a "ThreadState Exception - ActiveX Control cannot be instantiated because the current thread is not in a single thread apartment":
WebBrowser browser = new WebBrowser();
browser.Navigate(getSSOlink(ah1.InstitutionUserID, cardnumber));
Thread.Sleep(1000);
browser.Document.GetElementById("id25").InvokeMember("Click");
Thread.Sleep(1000);
browser.Document.GetElementById("cuRewardsLink").InvokeMember("Click");
browser.Visible = true;
Any help or thoughts would be appreciated,
I'm currently using the chrome driver with C# webdriver. one of the problems i'm facing is waiting for "exist" or "visible" is not working in my case because the modal window takes some time to go away. and i'm getting this error:
System.InvalidOperationException: unknown error: Element is not clickable at point (x,x). Other element would receive the click:
reason being that the modal backdrop is still present for a few seconds after I click OK/Cancel, but the element behind the backdrop is visible and clickable to selenium.
so how do i "wait" until the modal backdrop is completely gone before attempting to click something behind it? this is not a native javascript modal. it's a fancy third party modal that slides in and out of view with a transparent "cover" that prevents clicking on anything else when it's open.
You could user the ExpectedConditions API, such as:
var wait = new WebDriverWait(driver, TimeSpan.FromMinutes(1));
var element = wait.Until(ExpectedConditions.ElementIsClickable(By.Id("elementId")));
This will try during 1 minute until the element is clickable and is it does not happen it will throw an exception.
I have a pop up window doing some database queries(pop up popped up from the Default.aspx page).Now that I have the values I want to close the pop up and send these values to the Default.aspx page.
i tried Response.redirect(Default.aspx? + myvalues here) but it is opening the page in the pop up itself.
Any help please ?
Try to use Hidden value which store values hiddenly and again you can use it.
use it <asp:HiddenField runat="server"/> and store value in it from code behind
Opening and closing a popup is a client side event. After you have got your values from Db, you can simply close the popup using window.close(); and then open the the Default.aspx using window.location.href="Default.aspx? + myvalues;
Sorry, you cant to that purely in c# because popup are created on client, you will have to use java script. After your work is finished with the popup window get reference to the window that ipened it by checking the property 'window.opener'. have a look here Passing data between a parent window and a child popup window with jQuery and still you have any doubt ask it again. hope this helps.
i have two asp page,first one is home and second one is test. In home page user can select the type of test they want to take up, and after pressing start button a new window is open for taking the test. What i want to achieve is , after completing the test i want to close the test window and redirect to another page, and this redirect should hit the previously opened home window.
You don't clarify that you have popup window or blank window i am aspecting for the popup
In submit click button press
String x = "<script type='text/javascript'>window.opener.location.href='**Your new url of new page after completing test**';self.close();</script>";
ScriptManager.RegisterClientScriptBlock(this.Page,this.Page.GetType(), "script", x,false);
From self close you will be able to close current window and by window.opener.location.href you will able to redirect to new url
I hope this will help you
regards....:)
Yes you can do these 2 ways:
Window.Open() /.showmodalDialog() and keep parent and child open as well, or
On the home page click on your start button. Use code Response.Redirect("~/Test.aspx"); assuming it resides with Home.aspx. Take your test using ASp.Net wizard control or hiddens divs what ever suits you easy. Manipulate data on test page , save and get result to and from database using SqlConnection and SqlCommand assuming you have Sql Server as backend. Hold the table or any value in either cache or Session and throw it on your home page. Do whatever you want.
This will be not possible. What you can do is to redirect the user to the home page after completing the test, but this will be in the same windows.
I am working on mvc2 and i'm trying to open from javascript in a new window something.
if i only use inside the js function window.open("action/action/"+param) like this
function(){
window.open("action/action/"+param);
}
it works perfectly and the browser does not warn me that it is a new popup that i'm opening.
But if i make an ajax call before the window.open, the browser tells me that is a new popup and if i accept it.
if (json.data && json.data.URL)
{
window.open("action/action/"+param);//opens in a new window only if i accept popups
}
how can i make it work without the browser considering it as popup?
You can't popup a window "randomly" it needs to be right after the user has clicked something or did an action so that the browser doesn't think it's a random ad popup.
The window has to open as a direct result of the user's input. For example, you could open a new window inside a click handler. It's not full proof by any means, but it's one measure the browser can take to try and prevent unwanted popups.