Question

I'm running approx 30 scripted test cases (each test case is a script) in series and there are often failures that include: cannot identify specified element, element not present.

I've already added a lot of different methods to wait for an element to show up. Sometimes when it is clearly there, I guess Selenium has a hard time trying to find the element's id ?

I've included several

do{
    if(selenium.isElementPresent("id=resultTable_0_0"){
    selenium.click("viewResultForm:refresh_button");
    }
}while (!selenium.isElementPresent("id=resultTable_0_0"));

and

if(selenium.isElementPresent("id=resultTable_0_0"))
        selenium.isVisible("id=resultTable_0_0");

and

if(selenium.isElementPresent("id=resultTable_0_0_1_to"))
    selenium.click("resultTable_0_0_1_to");

always checking if an element is even present before doing something. This probably has a huge impact on performance, but for now I just want my scripts to run error-free, completely robust. I have this piece of code:

do{
    if(selenium.isElementPresent("id=resultTable_0_0")){
    selenium.click("viewResultForm:refresh_button");
    }
}while (!selenium.isElementPresent("id=resultTable_0_0"));

        if(selenium.isElementPresent("id=resultTable_0_0"))
            selenium.isVisible("id=resultTable_0_0");
        if(selenium.isElementPresent("id=viewResultForm:currentDetailViewType"))
            selenium.isVisible("id=viewResultForm:currentDetailViewType");
        if(selenium.isElementPresent("id=viewResultForm:currentSearchDateType"))
            selenium.isVisible("id=viewResultForm:currentSearchDateType");
        if(selenium.isElementPresent("id=viewResultForm:currentLegalEntity"))
            selenium.isVisible("id=viewResultForm:currentLegalEntity");
        if(selenium.isElementPresent("id=viewResultForm:currentRollupBy"))
            selenium.isVisible("id=viewResultForm:currentRollupBy");
        if(selenium.isElementPresent("id=viewResultForm:currentSecurityAltId"))
            selenium.isVisible("id=viewResultForm:currentSecurityAltId");
        if(selenium.isElementPresent("id=viewResultForm:currentSecurityAltIdType"))
            selenium.isVisible("id=viewResultForm:currentSecurityAltIdType");
        if(selenium.isElementPresent("id=viewResultForm:currentDepoViewType"))
            selenium.isVisible("id=viewResultForm:currentDepoViewType");
        if(selenium.isElementPresent("id=viewResultForm:currentBusinessDate"))
            selenium.isVisible("id=viewResultForm:currentBusinessDate");

        System.out.println("Success T13001");
        selenium.stop(); 

Even this will error out !!! and it wont fall through to reach selenium.stop and 'fake' a success. What can I do to build on the robustness of my scripts? Any help would be appreciated.

I'm using Selenium 2.20.0 on IE 8.

Was it helpful?

Solution

As per your question if its the problem of not finding the id of locators then try using other locators like css and xpath.

Apply selenium.waitforpagetoload when ever you move to a new page or you open a url.

If you are working on an ajax based application then selenium.waitforcondition would be gud to you.

Whereever you think that a locator may take some time to appear after some operation,Use proper waits for those elements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top