No Such element

Hi,

I want to take UIValue = 00:00, if the webelement is not found on UI.

I tried using catch exception, though it gives the same error.

And  also, I want to continue the execution, if such errors are occured during execution
used (@Test (always run = true)), though , my execution stops at ‘No such element’

Please help me in this 2 problems, need to be solved ?

 


if (driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)).isDisplayed()) {

UIValue = "00:00";

//UIValue = driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)).getAttribute("value");

}

else{

//UIValue = "00:00";

System.out.println("UI PayBucket:"+driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)));

UIValue = driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)).getAttribute("value");

}

System.out.println(UIValue);

Default Asked on November 28, 2014 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Hi,

    Try this:

    
    try {
    
    if (driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)).isDisplayed()) {
    
    //If Displayed then do this
    
    //Your Code
    
    }
    
    }catch(Exception e){
    
    //If not displayed, selenium will throw the error and your execution will come here
    
    UIValue = "00:00";
    
    //This is your else code
    
    System.out.println("UI PayBucket:"+driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)));
    
    UIValue = driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)).getAttribute("value");
    
    }
    
    System.out.println(UIValue);
    
    

    Regards,
    Lakshay Sharma

    Professor Answered on December 1, 2014.

    Please close the question if it is resolved.

    on December 2, 2014.

    Hi Lakshay,

    I tried , using  ‘isDisplayed’, to check for web element, but it returns NULL value, though the web element is present on UI ?

    Here is the stack trace:

    Starting ChromeDriver (v2.10.267521) on port 25955
    Only local connections are allowed.
    Warning: Usage of a local non-builtin name
    Excel PayBucket:JRM1
    Excel PayBucket Value:06:09
    null
    null
    PASSED: IntegrationTests

    ===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
    ===============================================

    on December 2, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.