我的代码中有一个复选框,我正在尝试选择。我也尝试过绝对的xpath,但它没有被选中。 代码粘贴在下面。有人可以帮帮我吗?
<label for="brandFilter*">ALL</label>
<div class="dijit dijitReset dijitInline dijitCheckBox dijitCheckBoxHover dijitHover dijitCheckBoxFocused dijitCheckBoxHoverFocused dijitHoverFocused dijitFocused" role="presentation" widgetid="brandFilter1">
<input id="brandFilter1" class="dijitReset dijitCheckBoxInput" type="checkbox" dojoattachevent="onclick:_onClick" dojoattachpoint="focusNode" name="brandFilter" style="-moz-user-select: none;" tabindex="0" aria-pressed="false"/>
</div>
<label class="dijitFocusedLabel" for="brandFilter1">Power Systems</label
我得到的错误是:
org.openqa.selenium.WebDriverException:未知错误:元素不是 点击(465,669)。
其他元素会收到点击:
<div id="results-loading" class="dealreg-load" style="filter:alpha(opacity=90); opacity:0.9;">...</div>
答案 0 :(得分:0)
当您搜索它时,看起来有一个加载指示符位于所需元素的顶部。等待所需的元素变为可点击:
WebDriverWait wait = WebDriverWait(driver, 10);
WebElement brandFilter = wait.until(ExpectedConditions.elementToBeClickable(By.ID("brandFilter1")));
brandFilter.click();
或者,等待加载指示消失:
WebDriverWait wait = WebDriverWait(driver, 10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.ID("results-loading")));
WebElement brandFilter = driver.findElement(By.ID("brandFilter1"));
brandFilter.click();
还有什么可以帮助:
最大化浏览器窗口:
driver.manage().window().maximize();
滚动查看元素:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView();", brandFilter);