我寫了下面的代碼,運行這段代碼後它返回空的String值。任何人都可以建議我解決這個問題嗎? 這裏我使用了gettext()方法。它不檢索鏈接名稱。爲什麼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");
}
}
}
}
輸出是:
Size is: 3
is selected
is not selected
is selected
PASSED: CheckingChkbox