我有以下幾行代碼:
WebElement x = driver.findElement(By.xpath<Locator>);
y = x.getText();
sysout(y);
if (y !=null)
{ <few statements here>}
else
{ sysout(" The value is blank in the UI");
<few other statements>`enter code here`
}
只要 y 不為空值,上面的代碼就可以正常運行。但是當 y 為空(即 null)時,我希望執行 else 塊。但事實并非如此,控制權仍然發生在 if 上。當我在條件顯示為空白之前將 y 值列印到控制臺時。我在這里錯過了什么?
uj5u.com熱心網友回復:
似乎您還需要空字串檢查:
代替:
if (y !=null)
試試這個:
if (y !=null && !y.isEmpty())
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/398267.html
