jeudi 24 décembre 2015

Selenium Continue Script when Element not Found using Try, Catch & Finally

I am using the below code snippet to Verify the visibility of an Element. If Element is not available i would like to call a method which i have included in catch block. Included a Click Event under Finally Block which i need to perform on both the cases, if an Element is available or After running a menthod when element is not available. However the below code doesn't seems to be working. I am still getting no such element exception even though the element is in try block.

    try
    {
        driver.findElement(By.xpath(".//table[@id='wishlist-table']/tbody/tr/td[5]/div/button")).isDisplayed();
    } 
    catch (NoSuchElementException e) 
    {
        System.err.println("Element not found: " + e.getMessage());
        AddItemtoWishlist();
    }
    finally
    {
        driver.findElement(By.xpath(".//table[@id='wishlist-table']/tbody/tr/td[5]/div/button")).click();
    }

Aucun commentaire:

Enregistrer un commentaire