Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi ,
i am new to selenium webdriver, i have to test "remember me" checkbox in login page with selenium webdriver. i dont have any idea. Kindly someone suggest me any ideas/coding.
Posted
Updated 6-Jun-16 0:03am

Java
public void selectCheckBox(WebDriver dri, String locateByPath)
{
	WebElement checkBox;
	checkBox = dri.findElement(By.name(locateByPath));
	if(!checkBox.isSelected())
	{
		checkBox.click();
	}		
}


This might help
 
Share this answer
 
if(dr.findelement(By.id("ID of Checkbox")).isSelected())
{
  
}
else()
{
 dr.findelement(By.id("ID of Checkbox")).click();
}


You can try this and this one will works and you can also check whether checkbox is checked or not.
 
Share this answer
 
public void ClickCheckbox(string boxName)
        {
            var CheckBoxesByClass = driver.FindElements(By.CssSelector("[class='checkbox']"));
            for (int i = 0; i < CheckBoxesByClass.Count(); i++)
            {
                if (CheckBoxesByClass[i].Displayed && CheckBoxesByClass[i].Text == boxName)
                {
                    CheckBoxesByClass[i].Click();
                    break;
                }
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900