gpt4 book ai didi

java - wait.until(ExpectedConditions.visibilityOf(userName)) 不起作用

转载 作者:行者123 更新时间:2023-11-30 06:23:37 26 4
gpt4 key购买 nike

在下面的第 33 行代码中,在 wait.until 附近出现以下错误消息

该行有多个标记 - 无法解析 com.google.common.base.Function 类型。它是从所需的 .class 文件间接引用的 - FluentWait类型中的方法until(Function)不适用于 参数(预期条件)

   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());
}
}

}

最佳答案

您看到的错误如下:

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)

让我们分析一下代码中发生了什么。

页面对象中,您已将WebElement定义为:

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

继续前进,您已尝试在方法中使用 WebElement :

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

所以基本上我们在这里试图等待间接引用 Angular WebElement userName 的可见性取决于属性 ng-model。在这种情况下,我们永远无法确定在方法 userName 中引用 WebElement 时是否会强制引用not NULL 值。它也可能是NULL

现在让我们看一下visibilityOf方法定义,它的定义为:

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

很明显,visibilityOf方法需要WebElement直接引用。因此,在 userName 缺乏确定值(not NULL)的情况下,WebDriverWait这是 FluentWait 的变体,显示错误。

关于java - wait.until(ExpectedConditions.visibilityOf(userName)) 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47656980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com