为什么GetText方法返回空字符串

1 java selenium-webdriver

我写了以下内容,运行此代码后,它返回空字符串值.任何人都可以建议我解决这个问题吗?这里我使用了gettext()方法.它不检索链接名称.

我的代码是:

package Practice_pack_1;

import java.util.List;    

import org.openqa.selenium.By;    
import org.openqa.selenium.WebDriver;    
import org.openqa.selenium.WebElement;    
import org.openqa.selenium.firefox.FirefoxDriver;    
import org.testng.annotations.AfterTest;    
import org.testng.annotations.BeforeTest;    
import org.testng.annotations.Test;   

public class CheckingUncheckingCheckbox {
    WebDriver driver;
    @BeforeTest
    public void open()
    {
    driver=new FirefoxDriver();
    driver.navigate().to("http://openwritings.net/sites/default/files/radio_checkbox.html");
}
@AfterTest
public void teardown() throws InterruptedException
{
    Thread.sleep(3000);
    driver.quit();
}
@Test
public void CheckingChkbox() throws InterruptedException{  
    WebElement parent = driver.findElement(By.xpath(".//*[@id='fruits']"));
    List<WebElement> children = parent.findElements(By.tagName("input")); 
    int sz= children.size();
    System.out.println("Size is: "+sz);
    for (int i = 0; i <sz; i++) 
    {
        boolean check= children.get(i).isSelected();
        if(check==true)
        {
            System.out.println(children.get(i).getText()+ "is selected");
        }
        else
        {
            System.out.println(children.get(i).getText()+ "is not selected");
        }
    }  
}
Run Code Online (Sandbox Code Playgroud)

}

输出是:

Size is: 3    
is selected    
is not selected 
is selected
PASSED: CheckingChkbox
Run Code Online (Sandbox Code Playgroud)

Des*_*ess 6

关于您的应用程序,您可能需要使用getAttribute("value")而不是getText()作为getText返回内部文本.