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 150 times
0

undetected Selenium
- 183,867
- 41
- 278
- 352

faa
- 7
- 7
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());

undetected Selenium
- 183,867
- 41
- 278
- 352