Waiting when using annotation

50 views
Skip to first unread message

Mohan Radhakrishnan

unread,
Dec 15, 2017, 8:42:18 AM12/15/17
to Selenium Users
Hi,

Is there a way to wait 'fluently' when I use annotations like this ? Is there a way to isolate the wait logic in this class ?


                         class SearchCase{

                                  @FindBy(how=How.XPATH, xpath  = "search")
                                  WebElement search

                         }

Thanks,
Mohan

shre...@gmail.com

unread,
Dec 15, 2017, 1:03:22 PM12/15/17
to Selenium Users
Yes you can. Read about Explicit and Fluent waits concept.

One good article for your reference: https://www.guru99.com/implicit-explicit-waits-selenium.html

~ Sreekanth

Mohan Radhakrishnan

unread,
Dec 18, 2017, 2:37:34 AM12/18/17
to Selenium Users
I use FluentWait. But when I use an annotation like this I am now sure how @FindBy can be intercepted to wait fluently.


Thanks,
Mohan

Mohan Radhakrishnan

unread,
Dec 18, 2017, 11:04:40 AM12/18/17
to Selenium Users
My question is this. Even though I use @FindBy I need to still use separate code to wait.


If I use the annotated WebElement  In ExpectedCondition, I get an exception indicating that ExpectedCondition doesn't accept a 'Proxy'.

Thanks,
Mohan

Krishnan Mahadevan

unread,
Dec 18, 2017, 11:52:18 AM12/18/17
to seleniu...@googlegroups.com

Mohan,

 

Try the following and see if that helps.

 

  1. Extend org.openqa.selenium.support.pagefactory.DefaultElementLocator
  2. Overload org.openqa.selenium.support.pagefactory.DefaultElementLocator#findElement in your sub-class created in (1) wherein you add your ExpectedCondition
  3. Extend org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory
  4. Override org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory#createLocator to return the instance of (1)
  5. Make use of org.openqa.selenium.support.PageFactory#initElements(org.openqa.selenium.support.pagefactory.ElementLocatorFactory, java.lang.Object) to intialise your page objects.

 

I think that should basically do.

 

PS: This is only my theory by looking at the code and I haven’t tried this out in practice.

 

For more information, you can refer to the below blog posts of mine:

 

https://rationaleemotions.wordpress.com/2016/09/05/understanding-pagefactory/

https://rationaleemotions.wordpress.com/2016/06/27/pagefactory-page-objects-and-locators-from-an-external-file/

 

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a9e1a9de-acb4-4804-9354-ba9bf2f8f9b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mohan Radhakrishnan

unread,
Dec 19, 2017, 4:24:57 AM12/19/17
to Selenium Users
I will try that. It will be hard to convince our developers to jump through that hoop. :-)


This is a simplistic method.

class LoginErrorPage{
 
                        
                @FindBy(how=How.XPATH, xpath= "//form/div[contains(@id,'error')]")
                WebElement loginError
 
                                 
                /*
                 * Check for a message indicating that login has failed
                 * Even though we use @FindBy it seems we still have to
                 * check explicitly using something like 'FluentWait'
                 */
 
 
                                                       
                public boolean isError(ChromeDriver
                                        ieDriver) throws Exception{
                   try{
                       Fluent fluent = new Fluent( ieDriver,
                                                  { wd -> wd.findElement(By.xpath("//form/div[contains(@id,'error')]"))});
                       loginError =fluent.waitFluently();
                    }catch( TimeoutException te){
                        loginError = null; // Should be null anyway
                    }catch( Exception e){
                                              
                          throw e;
                    }
 
 
                                   
                return loginError == null;
 
 
                                 
                }
            }

Thanks,
Mohan
Reply all
Reply to author
Forward
0 new messages