There are 52 page objects as follows, all of which has Strong tag containing a String called "Gideon".
How possibly can I get all of them by findElements method?
Asked
Active
Viewed 45 times
0
![](../../users/profiles/7429447.webp)
DebanjanB
- 118,661
- 30
- 168
- 217
![](../../users/profiles/13527540.webp)
farbod alidaei
- 17
- 6
1 Answers
0
The "quotes" are within a text nodes. So to retrieve the text you have to induce WebDriverWait for the visibility_of_all_elements_located()
and you can use either of the following Locator Strategies:
xpath
:List<WebElement> parentElements = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//strong[text()='Gideon']//.."))); for (WebElement parentElement:parentElements) System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].lastChild.textContent;", parentElement).toString());
xpath
with preceding:List<WebElement> parentElements = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//strong[text()='Gideon']//preceding::p[1]"))); for (WebElement parentElement:parentElements) System.out.println(((JavascriptExecutor)driver).executeScript("return arguments[0].lastChild.textContent;", parentElement).toString());
![](../../users/profiles/7429447.webp)
DebanjanB
- 118,661
- 30
- 168
- 217