I am a beginner test automator and I've been using direct XPATH references so far.
Now, I have the task of counting list items in a list that has no name.
I can copy the xpath using Chrome inspect but that path is very brittle. Any addition of element above it will make the path invalid. Looking for a more intelligent way to find the list.
I am using Selenium-JUnit-GeckoDriver.
Here is an example of my raw data:
...
<div class="entry-content" itemprop="text"><h3></h3>
<p> </p>
<p>texttexttexttexttexttexttexttext</p>
<p> </p>
<h4 class="p1"><span class="s1">List ONE</span></h4>
<hr>
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>
<h4 class="p1"><strong><span class="s1">List TWO</span></strong></h4>
<hr>
<ul>
<li>d</li>
<li>e</li>
</ul>
...
In my existing (and inadequate code), I do something like:
// Find the text input element by xPath (from chrome inspect)
WebElement element = driver.findElement(By.xpath("//*[@id=\"main\"]/div/div/main/article/div[3]/div[1]/ul[1]"));
List<WebElement> listItems = element.findElements(By.tagName("li"));
... and then I do my test on the list items.
How can I automate something like a method, where I give it a search string ("List ONE") and it returns all list items of the preceding list? (but not the list items of "List Two")?