!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: Findout if WebElement exists after PageFactory.init  (Read 1369 times)

dan hirsch

  • Web User
Findout if WebElement exists after PageFactory.init
« on: May 17, 2012, 08:43:22 PM »
Hi all, I have a small issue I can't find how to resolve.
 I have a page that is very dynamic according to customization for customers,
 hence I keep a page with all possible configuration WebElements as members.
 I init the Page using a PageFactory. as you understand by now, not all
 elements exists all the time so some of them are proxies pointing to non
 existing elements hence I can't event call the isDisplayed to find if the
 element exists.
 I can execute driver.findElements(By.name("myElementName")).size() > 0 but
 that means I am recalling the findElement that PageFactory
 is doing for me in init. how do I check if an already initiated element
 actually points to an existing element or whether it's a ghost element?
 --
 regards,
 Dan Hirsch

Daniel Wagner-Hall

  • Web User
Re: Findout if WebElement exists after PageFactory.init
« Reply #1 on: May 17, 2012, 08:43:49 PM »
Try actually using the particular element you want to use, e.g.
 element.getLocation() - this will throw a NoSuchElementException if
 the element is not present.
 On 7 July 2011 12:14, dan hirsch <hirsh....@gmail.com> wrote:
 

- Show quoted text -

Nikhil Bhoski

  • Web User
Re: Findout if WebElement exists after PageFactory.init
« Reply #2 on: May 17, 2012, 08:44:04 PM »
i am using wait to actually see if the element is actually present or not
 Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) {
           return new Function<WebDriver, WebElement>() {
             public WebElement apply(WebDriver driver) {
               return driver.findElement(locator);
             }
           };
         }
 WebDriverWait wait = new WebDriverWait(_driver, /*seconds=*/20);
 
WebElement userName =
 wait.until(presenceOfElementLocated(By.name("j_username")));
 
hope this serves the purpose.
 
Nikhil
 

- Show quoted text -

Selenium Webdriver

Re: Findout if WebElement exists after PageFactory.init
« Reply #2 on: May 17, 2012, 08:44:04 PM »

 

Related Topics

  Subject / Started by Replies Last post
0 Replies
165 Views
Last post February 22, 2012, 07:17:10 PM
by Warren Pollans
0 Replies
172 Views
Last post February 22, 2012, 08:37:27 PM
by Warren Pollans
0 Replies
167 Views
Last post February 23, 2012, 03:49:46 PM
by Warren Pollans
2 Replies
1535 Views
Last post March 28, 2012, 08:54:39 PM
by Michael Tamm
6 Replies
2578 Views
Last post April 11, 2012, 06:23:02 PM
by dan hirsch
4 Replies
1391 Views
Last post April 12, 2012, 04:55:07 PM
by Luke Inman-Semerau
1 Replies
331 Views
Last post April 12, 2012, 06:56:53 PM
by Daniel Wagner-Hall