WebDriver :: getText()仅获取部分字符串



我正在尝试使用getText(){selenium-webdriver}读取以下HTML代码,这是我的定位器和脚本行

@FindBy(xpath="//p[@class='radiobutton']") WebElement groupMsg;
System.out.println("This is the group message"+groupMsg.getText()); //msg display on console

o/p在控制台上::这是检查组Messageradio按钮'男性'

我显示它仅显示"性:男性"。没有获得"年龄组:5-15"。它是因为
而发生的(如果我错了,我认为请纠正我)

<p class="groupradiobutton">
Sex : Male
<br>
Age group: 5 - 15
</p>

任何人都可以为此提供解决方案吗?

以下代码为workig。

String a=driver.findElement(By.className("groupradiobutton")).getText();
System.out.Println(a);

这是在控制台中以下面的方式打印输出。

Sex : Male
Age group: 5 - 15

我已经用您给出的HTML进行了测试。

使用以下代码

driver.findElement(By.xpath("//p[@class='groupradiobutton')).getText();

最新更新