gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 06:38:44 26 4
gpt4 key购买 nike

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

最佳答案

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

关于java - 为什么 GetText 方法返回空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15922921/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com