如何检查“记住我”登录页面中的复选框与selenium webdriver [英] how to check "remember me" checkbox in login page with selenium webdriver

查看:98
本文介绍了如何检查“记住我”登录页面中的复选框与selenium webdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是selenium webdriver的新手,我必须使用selenium webdriver在登录页面中测试记住我复选框。我什么都不知道。请有人建议我任何想法/编码。

解决方案

  public  < span class =code-keyword> void  selectCheckBox(WebDriver dri, String  locateByPath)
{
WebElement checkBox;
checkBox = dri.findElement(By.name(locateByPath));
if (!checkBox.isSelected())
{
checkBox.click();
}
}





这可能会有所帮助


 if(dr.findelement(By.id(Checkbox的ID))。isSelected())
{

}
else()
{
dr.findelement(By.id(Checkbox的ID))。click();
}





你可以尝试这个,这个可行,你也可以检查是否选中了复选框。 / blockquote>

 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();
休息;
}
}
}


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.

解决方案

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



This might help


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.


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;
                }
            }
        }


这篇关于如何检查“记住我”登录页面中的复选框与selenium webdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆