[英]'id(java.lang.String)' in 'org.openqa.selenium.By' cannot be applied to '(org.openqa.selenium.By)'
I am trying to use By in selenium as a String to get my element but it is giving me the error "'id(java.lang.String)' in 'org.openqa.selenium.By' cannot be applied to '(org.openqa.selenium.By)'"我正在尝试使用 selenium 中的 By 作为字符串来获取我的元素,但它给了我错误“org.openqa.selenium.By”中的“id(java.lang.String)”无法应用于“(org .openqa.selenium.通过)'"
Please assist me Here is my code:请帮助我这是我的代码:
package adta;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
public class LoginPage extends BasePage {
public LoginPage(WebDriver driver) {
super(driver);
}
public By getUserNameLocator(){
return By.id("user-name");
}
public void open(){
driver.get("https://www.saucedemo.com/");
}
public boolean isLoaded(){
return wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(getUserNameLocator()))).isDisplayed();
}
public void login(String username, String password) {
driver.findElement(By.id(getUserNameLocator())).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.id("login-button")).click();
}
}
I have tried to search for answers online but no luck我试图在网上搜索答案,但没有成功
Since your getUserNameLocator()
method returns a By
type object and ExpectedConditions.visibilityOfElementLocated()
method receives a By
type value, you can use that inside isLoaded()
method as following:由于您的
getUserNameLocator()
方法返回By
类型 object 并且ExpectedConditions.visibilityOfElementLocated()
方法接收By
类型值,因此您可以在isLoaded()
方法中使用它,如下所示:
public boolean isLoaded(){
return wait.until(ExpectedConditions.visibilityOfElementLocated(getUserNameLocator())).isDisplayed();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.