Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
ramandas
Posts : 2
Join date : 2012-09-03

wait for control presence Empty wait for control presence

Wed Sep 26, 2012 2:09 pm
i have a scenario :
i have to wait for a control enable in specific time or if control is enable within time then go to next step.

EX : suppose a textbox should enable in 1 min and if text box is enable in 30 sec tn dont wait for 1 min. i used Thread.sleep() for wait.
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

wait for control presence Empty Re: wait for control presence

Thu Sep 27, 2012 1:34 pm
Code:
driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);

Here implicitlyWait waits maximum of 1 minute. If the web element enabled/displayed within 1 minute, then it executes next line without waiting for remaining time.
avatar
rohit kumar gupta
Active particpant
Active particpant
Posts : 24
Join date : 2012-09-19
Age : 34
Location : abc

wait for control presence Empty Re: wait for control presence

Sun Oct 21, 2012 6:17 pm
Hi popsha,

I had a doubt in the above code where are we specifying the web element which has to be enabled.
avatar
anemuday
Active particpant
Active particpant
Posts : 11
Join date : 2012-10-11

wait for control presence Empty Re: wait for control presence

Mon Oct 22, 2012 1:29 pm
I wrote my own custom method. This may help:
str_xPath = xpath of the object
MaxTime= maximum time to wait, which you have to pass in "Seconds"

Code:
public static void WaitTillButtonEnabled(String str_xPath,int MaxTime)
{



 long StartTime,EndTime;
 StartTime=new Date().getTime();
 long MaxT=MaxTime*1000;

 while(!driver.findElement(By.xpath(str_xPath)).isEnabled())
 {
  try
  {
  Thread.sleep(1000);
  }
  catch (InterruptedException e)
  {
  e.printStackTrace();
  }
  EndTime=new Date().getTime();
  if(EndTime-StartTime>MaxT) //The difference is returned in milliseconds
  break;
 }

}
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

wait for control presence Empty Re: wait for control presence

Mon Oct 22, 2012 3:17 pm
@ Rohit

Web elements are the one, we are dealing with in Selenium Webdriver directly. Components which are in a web page are called web element.
So, to accomplish the functionality of each web element, we use implicitlywait.

@ Anemuday

We cannot use your way of approach for every action in Webdriver. It will lead to brittle the script since Thread.sleep should be used in often.
Also, you didn't define the value for MaxTime.

Where as "implicitlyWait" universal waitr comand.
avatar
anemuday
Active particpant
Active particpant
Posts : 11
Join date : 2012-10-11

wait for control presence Empty Re: wait for control presence

Mon Oct 22, 2012 6:26 pm
One question popsha,

With your line of code, where you are associating with the control? What i mean is, Say i have 1000 Web Elements in my page and my control is 999th, and once all other controls loads then this control will be loaded.

And in another scenario, the webelement will be enabled only after some time gap say 10 Scec. Ex. i have few controls in my page and say upon clicking on Button1 all controls will be loaded, but after 10 secs my Button2 will be enabled. How to validate this?

I am new to Selenium/Java, i dont know the downside of Thread.sleep.

And in my function MaxTime is a parameter, that you have to pass to the function
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

wait for control presence Empty Re: wait for control presence

Tue Oct 23, 2012 8:25 am
Hi Anemuday,

Your question is perfectly correct for which implicitlyWait is made for. I briefed it in my first post in this thread. Let me explain it again.

Let's take your scenario, in that 500 web elements are static and remaining are dynamic. Here, browser's load time for each web element differs on their functionality. So, we use implicit wait command for all the web elements at single stretch ie., in @Before annotation rather than using explicit wait concept for each 500 web elements.
Code:
 @Before
    public void setUp() throws Exception {
       
           
  //    File file = new File("D:/Automate/Setup/IEDriverServer_Win32_2.24.2/IEDriverServer.exe");
    //    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
       
          driver = new InternetExplorerDriver();
       
          baseUrl = "http://xx.xx.xx.xx";
       
       
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
       
        driver.manage().window().maximize();
       
    }
In the above code, WebDriver wait for the web element to enable within 30 seconds. If the web element enabled less than 30 secs, let's say 10 secs, it will not wait for remaining 20 secs. It will move to next control.


For further more reference, have a look at below link
https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/_Qy1m5U_XpQ

Yes, i didn't notice the parameters passed to the method.
avatar
rohit kumar gupta
Active particpant
Active particpant
Posts : 24
Join date : 2012-09-19
Age : 34
Location : abc

wait for control presence Empty Re: wait for control presence

Wed Oct 24, 2012 5:35 pm
Hi Popsha,

This is how implicit wait is defined in the documentation.

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.
Sample code given there:-WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));
****My Understanding:-myDynamicElement statement will wait until it finds the element ****My Doubt:-What if i clik a button and a new field appears. Then when i use a find element on that will the implict statement provide the time even for this element or will I have to define a new implict time out statement.because according to documentation(Once set, the implicit wait is set for the life of the WebDriver object instance.)
avatar
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

wait for control presence Empty Re: wait for control presence

Thu Oct 25, 2012 9:23 am
Yes Rohit, as you mentioned it briefly. implcitWait set for life. Thus, no need of explicit wait again.
Usage of implicitWait is explained in my previous post for your perusal.
Sponsored content

wait for control presence Empty Re: wait for control presence

Back to top
Permissions in this forum:
You cannot reply to topics in this forum