I'm trying to select an element based on an already given element using Selenium and locators, but i'm trying to speed up the process and XPath isn't really helping me in this case.
This is the structure of the HTML i'm working with.
<div class="inner-article">
<h1>
<a class="name-link">
Text 1
</a>
</h1>
<p>
<a class="name-link">
Text 2
</a>
</p>
</div>
As of right now, I'm using these XPaths to find Text 1 and Text 2
text1 = driver.find_element_by_xpath("//a[contains(., 'Text 1')]")
text2 = driver.find_element_by_xpath("//a[contains(., 'Text 1')]/parent::h1/following-sibling::p/a[contains(., 'Text 2')]")
Since XPath has a noticeable delay, I was wondering if it's possible to use a different and much faster locator other than XPath. I can't really think of anything, because CSS selectors aren't an option and I can't think of a way to use the others.