java - 如何检查字段是否为空以及如何读取输入的文本?

标签 java selenium-webdriver

如何检查文本字段是否为空白,即如果给出如何将该文本存储到变量中,则没有给出输入?

最佳答案

访问 <input>value 属性网络元素。下面是一个例子:

WebElement inputBox = driver.findElement(By.id("inputBoxId"));
String textInsideInputBox = inputBox.getAttribute("value");

// Check whether input field is blank
if(textInsideInputBox.isEmpty())
{
   System.out.println("Input field is empty");
}

希望对您有所帮助!

关于java - 如何检查字段是否为空以及如何读取输入的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25499551/

相关文章:

java - 在 web 应用程序外部连接 Spring bean 的最简单/正确的方法是什么?

java - 如何使用retrofit2查找 map 中的标记?

python-3.x - Selenium webdriver python 元素屏幕截图无法正常工作

angularjs - 从模态中获取文本 : Protractor/Webdriver

具有泛型、比较器和排序错误的 Java 类层次结构

java - 将 tinyMCE 与 Jspell 集成以进行拼写检查?

java - org.postgresql.util.PSQLException : The column name grupo was not found in this ResultSet.(不同的错误)

java - 我收到 StaleElementReferenceException : element is not attached to the page document

selenium - 配置 ExtentReports 以提供准确的测试状态和失败截图

python - 在几次成功的 Selenium Geckodriver 任务后连接被拒绝(操作系统错误 111)(Python)