- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在下面的第 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/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!