我无法在应用程序中对“登录”按钮执行点击操作。
下面是HTML代码。您可以在最后一行找到确切的按钮元素。
<div class="form-group dl-padding-10">
<select class="form-control form-control-solid" name="SelectedRoleID" id="SelectedRoleID" onchange="removeBorderColor()" required="">
<option id="default_val" selected="" disabled="" hidden="">Profile </option>
<option value="15">Service Consultant</option>
<option value="11">DLBO Developer</option>
<option value="16">Admin Agent</option>
<option value="17">Team Leader</option>
<option value="18">Manager</option>
<option value="19">CV Mandator</option>
<option value="20">CV Agent</option>
<option value="21">Forensics Agent</option>
</select>
<div class="dl-align-left" id="show_text" style="color:red">
</div>
</div>
<div class="circle1-mask form-group" id="FingerprintContent" style="height:140px;z-index:2; background-image: none;">
<img src="Assets/img/fingerprint4.gif" id="fingerprint-img" data-status="active" style="height:140px; width:100px;" onclick="DeviceScript.scanFingerPrint(event)">
</div>
<div class="form-group dl-padding-10">
<button type="submit" id="register-btn" class="btn btn-block dl-button-primary dl-no-margin">Sign In (For Testing Purpose Only)</button>
</div>
</div>
</div>
</form> </div>
</div>
请帮助我使用合适的xpath来执行登录按钮上的点击操作。
还可以找到尝试的代码图像。Code
Xpath=”//button[contains(text(), 'Sign In (For Testing Purpose Only)')]”
(Or)
IWebElement Signin = driver.FindElement(By.Id("register-btn"));
Signin.Click();
(Or)
IWebElement Signinbutton = driver.FindElement(By.XPath("//button[contains(text(), 'Sign In (For Testing Purpose Only)')]"));
Actions action = new Actions(driver);
action.MoveToElement(Signinbutton).Click().Perform();
The error which i get:
OpenQA.Selenium.ElementClickInterceptedException : element click intercepted: Element <button type="submit" id="register-btn" class="btn btn-block dl-button-primary dl-no-margin">...</button> is not clickable at point (758, 646). Other element would receive the click: <div class="footer navbar-fixed-bottom">...</div>
答案 0 :(得分:0)
由于错误引用了页脚,因此您似乎缺少了一些html。
不是线程休眠的支持者,而是尝试一个,看看线程休眠是否允许页面加载。我想知道您的页面是否仍在加载并尝试单击。如果睡眠正常,我将其删除并移至element或尝试单击java。
Thread.Sleep(1000);
driver.FindElement(By.XPath("//button[contains(text(), 'Sign In')]")).Click();
driver.FindElement(By.Id("register-btn")).Click();
答案 1 :(得分:0)
尝试使用javascript:
IWebElement Signinbutton = driver.FindElement(By.XPath("//button[contains(text(), 'Sign In (For Testing Purpose Only)')]"));
IJavaScriptExecutor javascriptExecutor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("arguments[0].click();", Signinbutton );
答案 2 :(得分:0)
您收到的异常是因为您要单击的按钮在此元素的后面
<div class="footer navbar-fixed-bottom">...</div>
这似乎是页面的页脚。
您可以尝试以下任何步骤来解决该问题
滚动到登录按钮下方的任何元素(如果有)。您可以为此使用以下代码:
protected boolean scrollToElement(WebElement element)
throws NoSuchElementException, StaleElementReferenceException {
try {
jsExecutor.executeScript("arguments[0].scrollIntoView(true);", element);
return true;
} catch (NoSuchElementException e) {
logError("Element Not found exception when scrolling to element (JavaScript)", e);
throw e;
} catch (StaleElementReferenceException e) {
logError("Stale element exeption when scrolling to element (JavaScript)", e);
throw e;
}
}
String css= "display:none !important;"
protected void addCustomCSS(WebElement webElement, String css) {
registerCall(new Object() {
}.getClass().getEnclosingMethod().getName());
try {
String style = (String) jsExecutor.executeScript("arguments[0].getAttribute('style')", webElement);
jsExecutor.executeScript("arguments[0].setAttribute('style', " + css + ")", webElement);
stylesQueue.add(style);
} catch (Exception e) {
e.printStackTrace();
}
}