1

In the below code on 33rd line getting below error message near wait.until

Multiple markers at this line - The type com.google.common.base.Function cannot be resolved. It is indirectly referenced from required .class files - The method until(Function) in the type FluentWait is not applicable for the arguments (ExpectedCondition)

   package MPA;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginhelperClass {

    WebDriver driver;

    @FindBy(xpath = "//input[@ng-model='login.username']")
    private WebElement userName;

    @FindBy(xpath = "//input[@type='password']")
    private WebElement Password;

    @FindBy(xpath = "//input[@type='submit' and @value='Sign In']")
    private WebElement SignIn;

    @FindBy(xpath = "//span[@class='icon-avatar-round']")
    private WebElement Avatar;

    public LoginhelperClass(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public void logIn(String uName, String Pswd) throws InterruptedException {
        WebDriverWait wait=new WebDriverWait(driver,7);
        wait.until(ExpectedConditions.visibilityOf(userName));
        userName.sendKeys(uName);
        Password.sendKeys(Pswd);
        SignIn.click();
        try {
            Thread.sleep(4000);
            if (Avatar.isDisplayed()) {
                System.out.println("Login Successfull: " + uName);
            } else {
                System.out.println("Login failure check the credentials: " + uName);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

}




 package MPA;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginhelperClass {

    WebDriver driver;

    @FindBy(xpath = "//input[@ng-model='login.username']")
    private WebElement userName;

    @FindBy(xpath = "//input[@type='password']")
    private WebElement Password;

    @FindBy(xpath = "//input[@type='submit' and @value='Sign In']")
    private WebElement SignIn;

    @FindBy(xpath = "//span[@class='icon-avatar-round']")
    private WebElement Avatar;

    public LoginhelperClass(WebDriver driver) {
        this.driver = driver;
        PageFactory.initElements(driver, this);
    }

    public void logIn(String uName, String Pswd) throws InterruptedException {
        WebDriverWait wait=new WebDriverWait(driver,7);
        wait.until(ExpectedConditions.visibilityOf(userName));
        userName.sendKeys(uName);
        Password.sendKeys(Pswd);
        SignIn.click();
        try {
            Thread.sleep(4000);
            if (Avatar.isDisplayed()) {
                System.out.println("Login Successfull: " + uName);
            } else {
                System.out.println("Login failure check the credentials: " + uName);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

}
Mahen C
  • 11
  • 1
  • 6

2 Answers2

1

The error which you are seeing is as follows :

Multiple markers at this line - The type com.google.common.base.Function cannot be resolved. It is indirectly referenced from required .class files - The method until(Function) in the type FluentWait is not applicable for the arguments (ExpectedCondition)

Let us analyze what is happening in our code.

In the Page Object you have defined an WebElement as :

@FindBy(xpath = "//input[@ng-model='login.username']")
private WebElement userName;

Moving ahead you have tried to use the WebElement within the method :

public void logIn(String uName, String Pswd) throws InterruptedException {
    WebDriverWait wait=new WebDriverWait(driver,7);
    wait.until(ExpectedConditions.visibilityOf(userName));
    //
}

So basically here we were trying to wait for the visibility of an Indirectly Referenced Angular WebElement userName which is dependent on the attribute ng-model. In such circumstances we can never be sure that when the WebElement will be referenced within a method userName will mandatory reference to a not NULL value. It may be NULL as well.

Now let us have a look at the Method Defination of visibilityOf, it is defined as :

visibilityOf(WebElement element)
An expectation for checking that an element, known to be present on the DOM of a page, is visible.

So clearly, visibilityOf method expects a Direct Reference of the WebElement. Hence in absence of a definite value (not NULL) of userName, WebDriverWait which is a variant of FluentWait shows the error.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I am seeing same issue. what is weird is ..error is reproducible on Chrome but same code wait.until(ExpectedConditions.visibilityOf(element)); is working good on Firefox. Any suggestion ? – Mike ASP Sep 25 '19 at 04:12
0

Play with conditions with By/WebElement:

ExpectedConditions.presenceOfAllElementsLocatedBy(By)
ExpectedConditions.elementExists(By)
ExpectedConditions.elementIsVisible(By)
ExpectedConditions.elementToBeClickable(By/WebElement)
ExpectedConditions.visibilityOfAllElementsLocatedBy(By)
unickq
  • 1,497
  • 12
  • 18