0
@When("^user clicks linkedin button of the first news item$")
    public void user_clicks_linkedin_button_of_the_first_news_item()
    {
        try
        {
            firstSocialShareElement = driver.findElement(By.className("social-share-linkedin"));
            if(firstSocialShareElement!=null && firstSocialShareElement.isDisplayed())
            {
                firstSocialShareElement.click();
            }
        }
        catch(NoSuchElementException e)
        {

        }
    }
4

1 回答 1

0

It turns out it was a simple case of class name conflict.

Since i didn't specify the full qualified name of the exception as org.openqa.selenium. NoSuchElementException

It was considering it to be java.util. NoSuchElementException

and hence the exception was not getting caught.

Now the problem is resolved.

      try
        {
            firstSocialShareElement = driver.findElement(By.className("social-share-linkedin"));
            if(firstSocialShareElement!=null && firstSocialShareElement.isDisplayed())
            {
                firstSocialShareElement.click();
            }
        }
        catch(org.openqa.selenium. NoSuchElementException e)
        {

        }
于 2013-10-09T12:43:55.733 回答