Implicit and Explicit wait don't work.
How to fix it?
How to use FluentWait in PageFactory, so it would not be needed to use locator in the test.
Aim not to use Thread.sleep at all.
Tools used: Selenium, TestNG, WebDriverManager
Website is made on AngularJS.
public class LoginPage {
private WebDriver driver;
public StudioMenuPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver, this);
}
@FindBy(xpath = "//div[@class='login']")
private WebElement loginButton;
public WebElement getLoginButton() {
return loginButton;
}
}
public class TestBase {
public static WebDriver driver = null;
@BeforeTest()
public void initialize() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
}
public class LoginTest extends TestBase {
LoginPage loginPage;
@Test
private void makeLogin() {
loginPage = new LoginPage(driver);
// Does not work with Implicit Wait:
/*
loginPage.getLoginButton().click;
*/
// Works with Thread.sleep:
/*
Thread.sleep(4000);
loginPage.getLoginButton().click;
*/
// Does not work with Explicit Wait:
/*
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(loginPage.getLoginButton()));
loginPage.getLoginButton().click;
*/
// Works with FluentWait:
/*
new FluentWait<>(driver).withTimeout(Duration.ofSeconds(5)).pollingEvery(Duration.ofMillis(500))
.ignoring(WebDriverException.class)
.until(d -> {
WebElement el = d.findElement(By.xpath("//div[@class='login']"));
el.click();
return el;
});
*/
}
If Implicit and Explicit waiters are used, following error occurs:
org.openqa.selenium.WebDriverException: unknown error: Element <div class="login">...</div> is not clickable at point (225, 334). Other element would receive the click: <div id="cdk-overlay-0" class="cdk-overlay-pane" dir="ltr" style="pointer-events: auto; top: 316px; left: 201.5px;">...</div>
(Session info: headless chrome=73.0.3683.86)
(Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.14.4 x86_64) (WARNING: The server did not provide any stacktrace information)