0

Here I have to select the checkbox using selenium and I'm not able to select it. It has only one option of classname that I'm using but error is appearing:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"class name","selector":"um-icon-android-checkbox-outline"}

code

@Test
public void validemail()
{
    WebElement email=driver.findElement(By.id("username-15"));
    email.clear();
    email.sendKeys("ceicateviewer");

    WebElement password=driver.findElement(By.id("user_password-15"));
    password.clear();
    password.sendKeys("1256Aa");

    WebElement showpassword=driver.findElement(By.className("um-icon-android-checkbox-outline"));
    showpassword.click();

    WebElement keepsignin=driver.findElement(By.className("um-icon-android-checkbox-outline"));
    keepsignin.click();


    /*WebElement login=driver.findElement(By.className("um-button"));
    login.click();*/
}
S.I.
  • 3,250
  • 12
  • 48
  • 77

1 Answers1

0

So, I get from your code, that it seems that checkbox showpassword and checkbox keepsignin have the same classname. That means, there are at least 2 elements have classname um-icon-android-checkbox-outline, that's why when you use driver.findElement, driver doesn't know which one. In this case you have to use driver.findElements. You can try this:

List<WebElement> checkboxes = driver.findElements(By.className("um-icon-android-checkbox-outline"));
// assuming there are only 2 elements have this classname, and in this order
checkboxes.get(0).click();  // click on showpassword
checkboxes.get(1).click();  // click on keepsignin

Hope it helps.

Ragnarsson
  • 1,715
  • 7
  • 41
  • 74
  • if i am using this code then(it throws this error):::::java.lang.Error: Unresolved compilation problems: List cannot be resolved to a type get cannot be resolved List cannot be resolved to a type get cannot be resolved – shweta kaushik Jun 04 '18 at 10:30
  • @shwetakaushik: is `import java.util.List` present in your Imports? The error indicates that you might use the wrong import. – Ragnarsson Jun 04 '18 at 12:36
  • import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; I USED THIS IMPORTS WITH CODE Listshowpassword=get.driver.findElement(By.className("um-icon-android-checkbox-outline")); showpassword.get.click(); List keepsignin=get.driver.findElement(By.xpath("um-icon-android-checkbox-outline")); keepsignin.get.click(); THEN IT GIVES ERROR java.lang.Error: get cannot be resolved @Ragnarsson – shweta kaushik Jun 05 '18 at 05:02
  • @shwetakaushik well, you did wrong in your code. 1) why `get.driver.findElement` ?!. I don't get it. that's why you got that's error `get cannot be resolved`. 2) `findElement` return a single WebElement, not a List. Please check my answer again. – Ragnarsson Jun 05 '18 at 07:36