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:
Rutvi SoniRutvi Soni
asked Oct 14, 2017 at 9:19
-
2Can you provide the html code for the respective elements on which action should be donethe_coder– the_coder2017年10月14日 14:36:43 +00:00Commented Oct 14, 2017 at 14:36
-
i have add screenshot please checkRutvi Soni– Rutvi Soni2017年10月16日 05:47:35 +00:00Commented Oct 16, 2017 at 5:47
-
Can you please put whole error stack trace ?Sagar007– Sagar0072017年10月16日 05:59:13 +00:00Commented Oct 16, 2017 at 5:59
1 Answer 1
As I understand from this stack trace it is issue of Element is not clickable
.
For this exception, following problem :
- 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();
}
- Web Element is not on visible screen or Visible area:
- Scroll to that element and perform click operation
- Some ajax event perform while clicking :
- Same solution as Point Num : 1
Note : Choose your problem and perform the solution.
answered Oct 16, 2017 at 7:58
Explore related questions
See similar questions with these tags.