我在selenium + pure java中面临一个问题。我在屏幕上有这个toggle,我想知道它什么时候是活动的。
区别在于button的类。
我写了这段代码。
public Boolean isDealActive() throws Exception
{
String test1 = getWebDriver().findElement(By.xpath("//*[@id='switch_deal_status_toggle']//button")).getAttribute("checked");
Boolean test2 = getWebDriver().findElement(By.xpath("//*[@id='switch_deal_status_toggle']//button")).isSelected();
String test3 = getWebDriver().findElement(By.xpath("//*[@id='switch_deal_status_toggle']")).getAttribute("checked");
Boolean test4 = getWebDriver().findElement(By.xpath("//*[@id='switch_deal_status_toggle']")).isSelected();
return isElementSelected(DEAL_STATUS_XPATH);
}
当我使用get属性时,结果是nullwhen我使用is selected时,结果是false和not true.the toggle now is ON,我只是得到错误的结果can someone advise? **不要注意return语句,在得到selenium的正确答案后,我将会修正它
试试下面的实现
WebElement toggleBtn = driver.findElement(By.xpath("//*[@id='switch_deal_status_toggle']/button"));
String classAttributes = toggleBtn.getAttribute("class");
if (classAttributes.contains("ant-switch-checked")) {
// checked
} else {
// not checked
}