0

I'm writing testcases to select 7 radio buttons. While select the radio button it displays run time error.

I have tried with below code :

public void selecttemplate()
{

    List<WebElement> rdBtn = driver.findElements(By.name("Template_Type"));             
    int size=rdBtn.size();

    for(int i=0;i<size;i++)
    {
        String val=rdBtn.get(i).getAttribute("value");

        if(val.equals("Documents"))
        {
            rdBtn.get(i).click();
            break;
        }
    }
    WebElement save=driver.findElement(By.name("register-button"));
    save.submit();
}

Below is error snap:

enter image description here

enter image description here

3
  • 2
    Can you provide the html code for the respective elements on which action should be done
    – the_coder
    Commented Oct 14, 2017 at 14:36
  • i have add screenshot please check
    – Rutvi Soni
    Commented Oct 16, 2017 at 5:47
  • Can you please put whole error stack trace ?
    – Sagar007
    Commented Oct 16, 2017 at 5:59

1 Answer 1

1

As I understand from this stack trace it is issue of Element is not clickable.

For this exception, following problem :

  1. Page is not loaded properly. So you need to wait for page and all component to load. Here is the code :
     public void selecttemplate()
     {

    WebDriverWait wait = new WebDriverWait(driver, 20);
    List<WebElement> rdBtn = driver.findElements(By.name("Template_Type"));             
    int size=rdBtn.size();

    for(int i=0;i<size;i++)
    {
    String val=rdBtn.get(i).getAttribute("value");

    if(val.equals("Documents"))
    {
        // wait - recommended case 
        wait.until(ExpectedConditions.elementToBeClickable(rdBtn.get(i)));

       //Use Thread.sleep(); Not recommended. Use only in last working case 
       //Thread.sleep(4000);
       rdBtn.get(i).click();
        //Thread.sleep(4000);
        break;
    }
    }
    WebElement save=driver.findElement(By.name("register-button"));
    save.submit();
    }

  1. Web Element is not on visible screen or Visible area:
  • Scroll to that element and perform click operation

  1. Some ajax event perform while clicking :
  • Same solution as Point Num : 1

Note : Choose your problem and perform the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.