我写了以下内容,运行此代码后它返回空字符串值。有人可以建议我解决这个问题吗?这里我使用了 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