这是site。我需要在selenium webdriver中选中复选框。 Code
double[]
我试过了:
<div class="login-form__checkbox">
<div class="fblock active">
<div class="focusbox">
<span class="abs" style="width:0px; height:0px; overflow:hidden; font-size:0px; zoom:1;">
<input id="checkbox_accept-terms" type="checkbox" name="register[rules]"/>
</span>
<label class="icon f_checkbox inlblk vtop selected" relname="register[rules]" for="checkbox_accept-terms"/>
<label class="selected" for="checkbox_accept-terms">
<strong>Rules</strong>
</label>
</div>
</div>
</div>
和
driver.findElement(By.id("checkbox_accept-terms")).click();
答案 0 :(得分:1)
我尝试直接点击INPUT
,但由于某种原因它不允许这样做。您只需单击LABEL
,然后选中该复选框即可。这段代码有效。
driver.findElement(By.cssSelector("label[for='checkbox_accept-terms']")).click();
答案 1 :(得分:0)
这是chrome在检查元素时提供的xpath。
//label[@class="icon f_checkbox inlblk vtop"]
这是对我有用的相对xpath:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
答案 2 :(得分:0)
您也可以使用JavaScriptExecutor执行任务,使用您尝试过的相同定位器。请查看下面的代码段:
JavascriptExecutor jse = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.id("checkbox_accept-terms"));
jse.executeScript("arguments[0].click();", element);