Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium waitForCondition

Tags:

ajax

selenium

I am doing Selenium testing for the first time. On the homepage, I call some AJAX, and i want Selenium to wait for the element to load finish. I not sure it works, but i just type selenium and the waitForCondition are able to choose.

I not matter what I choose it always return "false". I do not now if the waitForCondition even work?

How can I test if it works? And what am I doing wrong in this codes?

 selenium.waitForCondition("//input[@name='Report'", "3000");
 selenium.waitForCondition("//*[@id='MyTable']", "3000");
 selenium.waitForCondition("css=.someClass2", "3000");

If I implement by own class - it return "true"

private boolean isElementPresent(By by) {
    try {
        driver.findElement(by);
        return true;
    } catch (NoSuchElementException e) {
        return false;
    }
}

isElementPresent(By.xpath("//*[@id='MyTable']")) - return "true"

like image 615
boje Avatar asked Nov 27 '12 16:11

boje


2 Answers

waitForCondition is for Javascript calls only, not for waiting for elements to load.

What you have in isElementPresent is fine. I would combine it with explicit waits to be a bit more accurate about when an element is actually loaded and present on the screen:

http://seleniumhq.org/docs/04_webdriver_advanced.html

like image 128
Arran Avatar answered Nov 02 '22 09:11

Arran


C#

You can do it like this:

First of all you can set timeout value for the condition.

Then you can use the condition.

var Wait = new WebDriverWait(GlobalDriver, TimeSpan.FromMinutes(1));
Wait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.XPath("xPath"))));

OR

Wait.Until(driver => driver.FindElement(By.XPath("xPath")));

Thats all.

like image 20
Mohsin Awan Avatar answered Nov 02 '22 10:11

Mohsin Awan