Switching to new window when it's ready

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Switching to new window when it's ready

Greg Martz-2
Greetings.

I know how to switch back and forth when a new window opens during my testing.  I'm running into a problem when the script is run on a slower machine, or when the network is slow.  What happens, is it attempts to switch to the new window before it's even open  I've solved it by putting in a long sleep, but there has to be a better way:

driver.findElement(By.xpath("//button[contains(., 'Create Test Request')]")).click();
Thread.sleep(6000);
//A new window has opened, we need to save the parent window, then switch to the newly opened window
String parentHandle = driver.getWindowHandle(); // get the current window handle
for (String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("RadioButtons0")));


What happens in the above code is the wait.until times out on slower machines/network conditions if the Thread.sleep is removed. 

Thanks!
Greg

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Switching to new window when it's ready

Cédric Beust ♔-2
This is not a TestNG question, please ask it somewhere else.

Thanks.

-- 
Cédric


On Thu, Mar 10, 2016 at 2:02 PM, Greg Martz <[hidden email]> wrote:
Greetings.

I know how to switch back and forth when a new window opens during my testing.  I'm running into a problem when the script is run on a slower machine, or when the network is slow.  What happens, is it attempts to switch to the new window before it's even open  I've solved it by putting in a long sleep, but there has to be a better way:

driver.findElement(By.xpath("//button[contains(., 'Create Test Request')]")).click();
Thread.sleep(6000);
//A new window has opened, we need to save the parent window, then switch to the newly opened window
String parentHandle = driver.getWindowHandle(); // get the current window handle
for (String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("RadioButtons0")));


What happens in the above code is the wait.until times out on slower machines/network conditions if the Thread.sleep is removed. 

Thanks!
Greg

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Switching to new window when it's ready

Greg Martz-2
My apologies, sent to wrong group.


Thanks!
Greg

Greg Martz
Test Analyst III  |  (425)416-5039  |  [hidden email] 

"Confidentiality Notice:  This e-mail message, including any attachments, is for the sole use to the intended recipient(s) and may contain confidential and privileged information.  Any unauthorized review, use, disclosure or distribution is prohibited.  If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message."


On Thu, Mar 10, 2016 at 2:30 PM, Cédric Beust ♔ <[hidden email]> wrote:
This is not a TestNG question, please ask it somewhere else.

Thanks.

-- 
Cédric


On Thu, Mar 10, 2016 at 2:02 PM, Greg Martz <[hidden email]> wrote:
Greetings.

I know how to switch back and forth when a new window opens during my testing.  I'm running into a problem when the script is run on a slower machine, or when the network is slow.  What happens, is it attempts to switch to the new window before it's even open  I've solved it by putting in a long sleep, but there has to be a better way:

driver.findElement(By.xpath("//button[contains(., 'Create Test Request')]")).click();
Thread.sleep(6000);
//A new window has opened, we need to save the parent window, then switch to the newly opened window
String parentHandle = driver.getWindowHandle(); // get the current window handle
for (String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle); // switch focus of WebDriver to the next found window handle (that's your newly opened window)
}
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("RadioButtons0")));


What happens in the above code is the wait.until times out on slower machines/network conditions if the Thread.sleep is removed. 

Thanks!
Greg

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.