[英]How to check if a field is blank and how to read the entered text?
如何檢查文本字段是否為空白,如果給出如何將該文本存儲到變量中,則不給出輸入?
<input>
web元素的訪問值屬性。 以下是一個例子:
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");
}
希望能幫助到你!
WebElement ele = driver.findElement(by locator)); //find the text field
if (ele.getAttribute("value").isEmpty()) {
//Do something if the text field is empty
}
else {
//Store the value
String store=ele.getAttribute("value");
}
var element = driver.findElement(webdriver.By.id("your elements id"));
//store text
var text = element.getText();
//store value
var value = element.getAttribute("value");
//after that you can do anything you want with these variables.
wd.find_element_by_id('foo').get_attribute('value')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.