Java equivalent to waitForElement???

222 views
Skip to first unread message

Lumbee

unread,
Aug 7, 2010, 9:17:46 AM8/7/10
to Selenium Users
Hey guys, I'm trying to get my tests to run more reliably, and am
trying to add more waits and detectors. I am using Java, and the only
options I have are waitForFrametoLoad and waitForCondition. Which
would you guys recommend for waiting for an element to load. Is
waitForFrametoLoad only for iFrames, or can I use it with any element.
I tried it with some xpaths without much luck. The documentation for
waitForCondition says it will run a "javascript snippet". Any
suggestions on what kind of javascript snippet I can insert here to
verify an element has loaded. Any feedback appreciated...thanx!

Gergely

unread,
Aug 7, 2010, 5:07:17 PM8/7/10
to Selenium Users
Hi Mate.

Try my framework for web automated testing.

In the Utility class you will find a bunch of code that works on
problems like that.

Like : waitForAjaxRequestDone, waitForElementToAppear,
waitForAttributeToChange etc,etc.

https://sourceforge.net/projects/webauthfw/

You will find the source code under download.

And give us credit if you like it. :)

Cheers,
Gergely.

Marcus Döring

unread,
Aug 8, 2010, 4:55:19 AM8/8/10
to Selenium Users
I wrote my own"helper"-Classes for this stuff.
Basically what I did was using .isElementPresent(xpath)
and .isVisible(xpath) pepped up with some Thread-sleep(milliSeconds)
and some exception handling.

This way you'll be able to easily modifie your "wait"-Methods and
you'll know what is going on when something does go wrong.
(not that using Gregely's framework would be a bad idea)

Simon Stewart

unread,
Aug 8, 2010, 8:32:30 AM8/8/10
to seleniu...@googlegroups.com
You could use the ConditionRunner[1], which ships as part of Selenium.
You can use it by doing something like:

ConditionRunner runner = new DefaultConditionRunner(selenium);
Condition condition = new Text("cheese");
runner.waitFor(condition);

If you're using Selenium WebDriver, from the 2.0 alphas, you can use
"Wait" interface:

Wait<WebDriver> wait = new WebDriverWait(driver, 15);
ExpectedCondition<WebElement> condition =
new PresenceOfElement(By.id("foo"));
WebElement found = wait.until(condition);

Writing "PrescenceOfElement" is left as an exercise for the reader :)

Simon

[1] http://selenium.googlecode.com/svn/trunk/docs/api/java/com/thoughtworks/selenium/condition/ConditionRunner.html

> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
>
>

Ross Patterson

unread,
Aug 9, 2010, 9:40:34 AM8/9/10
to seleniu...@googlegroups.com
Our WaitForElementPresent() method uses WaitForCondition("selenium.isElementPresent(\"" + locator.Replace("\"", "\\\"") + "\");", timeout) - when it evaluates to true, WaitForCondition() returns. If it never does, WaitForCondition() throws a timeout exception. The Replace() call is to make any double-quotes in the locator survive the C#-to-JavaScript translation.

Ross

--

Lumbee

unread,
Aug 9, 2010, 10:32:14 AM8/9/10
to Selenium Users
...thanx for all the responses guys. Thanx Ross, your suggestion seems
to be the easiest to implement, and seems to have gotten me over the
hump!
Reply all
Reply to author
Forward
0 new messages