嗯,我正在用Angular和Java与Selenium设计的页面上进行测试。当查询数据库或页面加载其代码时,将显示:
<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(定位器),但是没有用...
您需要等待loader成为invisible或hidden为invisibilityOfElementLocated()
引入WebDriverWait,并且可以使用以下Locator Strategies中的任何一个:] >
cssSelector
:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("span.loading)));
xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//span[@class='loading'])));
是invisible或hidden,您可以为一旦loader
elementToBeClickable()
引入WebDriverWait并按以下方式调用click()
:cssSelector
:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("span.loading)));
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("clickable_element_css"))).click();
xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//span[@class='loading'])));
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("clickable_element_xpath"))).click();
您可以在Element MyElement is not clickable at point (x, y)… Other element would receive the click中找到相关的讨论