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

Selenium WebDriver::getText()只获取部分字符串,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我正在尝试使用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::这是组消息选中单选按钮“男性” 正如我所展示的,

我正在尝试使用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::这是组消息选中单选按钮“男性”

正如我所展示的,它只展示了性别:男性。没有得到年龄组:5-15岁。这是因为我认为如果我错了,请纠正我

<p class="groupradiobutton">
Sex : Male
<br>
Age group: 5 - 15
</p>
有人能给出解决方案吗?

使用下面的代码

driver.findElement(By.xpath("//p[@class='groupradiobutton')).getText();
下面的代码正在运行

String a=driver.findElement(By.className("groupradiobutton")).getText();
System.out.Println(a);
这是在控制台中打印输出,如下所示

Sex : Male
Age group: 5 - 15

我已经用您提供的html进行了测试。

您使用的定位器是什么,我可以看到有一个标签正在打开。在哪里结束?请提供您在脚本中使用的定位器和java代码。您尝试了什么?请分享你的代码它不可能只打印文本的第一部分。getText函数不理解标记。没错,getText函数不理解br标记,所以它必须打印所有内容。thx Sai。看来你是对的。看起来我使用了错误的类名,因此显示了错误的消息。@GaurangShah::Agree getText不会为br标记而烦恼。它按原样打印文本。