[英]How to capture all wrapped text of multiple paragraph tags in selenium?
I am facing one problem .我面临一个问题。 I made a function for capturing the value of paragraph tag .
我做了一个函数来捕获段落 tag 的值。 For a single paragraph its perfectly working but there are so many paragraph tags .
对于单个段落,它完美地工作,但有很多段落标签。 How can i retrieve these values in a function ?
如何在函数中检索这些值?
public String captureText(WebDriver driver) {
String captureValue;
captureValue = driver.findElement(By.xpath("//span[text()='Subtitles']//following::p[1]")).getText();
return captureValue;
}
My function is looking like above.我的功能看起来像上面一样。
Try with below code :尝试使用以下代码:
//create a list to store all the paragraph text values
//Store all the paragraphs element in another list
public List<String> captureText(WebDriver driver) {
List<String> allParagraphsValues = new ArrayList<String>();
List<WebElement> allParagraphs = driver.findElements(By.xpath("//span[text()='Subtitles']//following::p"));
//Loop through all the Paragraph elements and add the text in a list
for(WebElement ele : allParagraphs){
allParagraphsValues.add(ele.getText());
}
return allParagraphsValues;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.