Selenium 如何根据HTML使用xpath标识复选框
及 两者都返回false。请帮助我如何选中复选框Selenium 如何根据HTML使用xpath标识复选框,selenium,selenium-webdriver,xpath,css-selectors,webdriver,Selenium,Selenium Webdriver,Xpath,Css Selectors,Webdriver,及 两者都返回false。请帮助我如何选中复选框 提前感谢。尝试使用以下XPath获取所需复选框: boolean s1 = driver.findElement(By.xpath("//*form[@id='userinfo' and @name='userinfo']/div[7]/div/label/input[@name='terms']")).isDisplayed(); System.out.println(s1); 您也可以尝试通过@name找到它: //div[.='I ag
提前感谢。尝试使用以下XPath获取所需复选框:
boolean s1 = driver.findElement(By.xpath("//*form[@id='userinfo' and @name='userinfo']/div[7]/div/label/input[@name='terms']")).isDisplayed();
System.out.println(s1);
您也可以尝试通过@name
找到它:
//div[.='I agree to Muvi’s Term of Service']//input
还要注意,在第二个XPath中,这部分//*表单
在语法上是不正确的。您应该指定标记名//form
以仅获取form
节点,或者指定通配符//*
以获取具有任何名称的节点,但不能同时指定两者以在文本关联为服务条款的复选框上调用单击()
- XPath:
- CSS:
您可以在下面使用
Xpath
"label.checkbox.checkbox-inline > input[name=terms]"
或
CSS选择器
".//*[@id='userinfo']/div[7]/div/label/input"
您是否能够成功处理表单中的其他元素?
driver.findElement(By.name("terms"));
"//label[@class='checkbox checkbox-inline']/input[@name='terms']"
"label.checkbox.checkbox-inline > input[name=terms]"
".//*[@id='userinfo']/div[7]/div/label/input"
.checkbox > input:nth-child(1)