[英]JAVA: How can we print the parameter value in console?
Class1:has a reusable function like this- Class1:具有这样的可重用功能-
public class Class1 {
WebDriverWait wdw = new WebDriverWait(driver, 10);
public WebElement getElement(WebElement element) {
wdw.until(ExpectedConditions.elementToBeClickable(element));
}
}
Class2: 第2类:
public class Class2 {
public static void main(String[] args) {
ge.getElement(login_button).click();
}
}
Now how can I get "login_button" print in console (with some more message)if this element not present on page or timed out etc 现在,如果此元素在页面上不存在或超时等,如何在控制台中获得“ login_button”打印(还有更多消息)
I have tried: Class1: 我已经尝试过:Class1:
public class GetElement {
WebDriverWait wdw = new WebDriverWait(driver, 10);
public WebElement getElement(WebElement element) {
try {
return wdw.until(ExpectedConditions.elementToBeClickable(element));
} catch (Exception e) {
System.err.println(element);
}
return null;
}
}
But printing this element gives this in console: 但是打印此元素可以在控制台中实现:
Proxy element for: org.openqa.selenium.support.pagefactory.DefaultElementLocator@57250572
instead of Proxy element for: org.openqa.selenium.support.pagefactory.DefaultElementLocator@57250572
代替
login_button
You have WebElement & want to print it's name, then you can use getText() method of WebElement interface. 您拥有WebElement并想打印它的名称,然后可以使用WebElement接口的getText()方法。 Look at this WebElement - java.lang.String getText() .
查看此WebElement-java.lang.String getText() 。
public class GetElement {
WebDriverWait wdw = new WebDriverWait(driver, 10);
public WebElement getElement(WebElement element) {
try {
return wdw.until(ExpectedConditions.elementToBeClickable(element));
} catch (Exception e) {
System.err.println(element.getText());
}
return null;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.