Selenium网络驱动程序等待在覆盖的情况下似乎不起作用



有一个覆盖层(灰色半透明屏幕(,每当单击登录按钮并停留几秒钟时,就会出现。正因为如此,Selenium Web 驱动程序无法找到这些元素,因为这种覆盖层会隐藏它们一段时间,或者至少在我看来是这样。我该如何处理?我认为Thread.sleep在这里不是一种有效的方法。

我试过了-

public void login(){
WebDriverWait wait = new WebDriverWait(driver, 60);     
wait.until(ExpectedConditions.invisibilityOfElementLocated((By.id("ajax-overlay"))));
wait.until(ExpectedConditions.elementToBeClickable((By.id("okbutton))));
driver.findElement(By.id("username)).sendKeys("admin");
driver.findElement(By.id("password")).sendKeys("admin123");
driver.findElement(By.id("okbutton")).click();   
wait.until(ExpectedConditions.invisibilityOfElementLocated((By.id("ajax-overlay"))));
}

但似乎没有任何效果,我仍然收到错误 -

org.openqa.selenium.WebDriverException: unknown error: Element <button id="loginDialog:okButton" name="loginDialog:okButton" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-panel-titlebar-icon synchronous" onclick="PrimeFaces.ab({source:'loginDialog:okButton',process:'loginDialog:okButton loginDialog:username loginDialog:password loginDialog:okButton',update:'startingCashFocus loginDialog:dialogFocus loginDialog:lblPassword loginDialog:lblUsername loginDialog:messages',oncomplete:function(xhr,status,args){handleLoginAttempt(xhr, status, args, loginWidget, null); ;}});return false;" tabindex="1" type="submit" role="button" aria-disabled="false">...</button> is not clickable at point (931, 250). Other element would receive the click: <div id="ajax-overlay" class="ui-blockui ui-widget-overlay ui-helper-hidden eternal" style="display: block;"></div>

此外,没有办法找出覆盖 id,值得庆幸的是,Selenium 在其错误详细信息中给出了它。

尝试使用以下方法之一单击元素,这将解决此异常:

Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.id('okbutton'))).click().perform(); 

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", driver.findElement(By.id('okbutton')));

相关内容

  • 没有找到相关文章

最新更新