嗯,我正在使用 Selenium 在 Angular 和 Java 设计的页面上进行测试。当对数据库进行查询或页面在其代码中加载时,将显示以下内容:
<span _ngcontent-c0 class = "loading"> </span>
加载完成后,它会发生如下变化:
<span _ngcontent-c0 class = "loading" hidden> </span>
我的问题是这个“加载”正在拦截我在测试中发送的点击:
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <a class="white-text" id="aaidEntidadBancaria" title="Apply"> ... </a> is not clickable at point (460, 502) . Other element would receive the click: <span _ngcontent-c0 = "" class = "loading"> </span>
我可以使用什么样的等待?我已经尝试过 invisibilityOfElementLocated (定位器),但它不起作用......
最佳答案
您需要等待加载器不可见或隐藏,从而引发的WebDriverWait invisibilityOfElementLocated()
并且您可以使用以下任一 Locator Strategies :
css选择器:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("span.loading")));
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//span[@class='loading']")));
<小时/>You can find a relevant discussion in Selenium invisibilityOf(element) method throwing NoSuchElementException + WebDriverWait.ignoring(NoSuchElementException.class) is not working
一旦加载器不可见或隐藏,您可以为elementToBeClickable()引发WebDriverWait
并调用 click()
,如下所示:
css选择器:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("span.loading"))); new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.white-text#aaidEntidadBancaria[title='Apply']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//span[@class='loading']"))); new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='white-text' and @id='aaidEntidadBancaria'][@title='Apply']"))).click();
You can find a relevant discussion in Element MyElement is not clickable at point (x, y)… Other element would receive the click
关于java - 如何等待项目完成加载?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59094751/