<aside class="reply-flap js-captcha">
<ul>
<li>
<h1>contact name:</h1>
<p>joel Rupp</p>
</li>
<li class="reply-tel">
<h1>
<a class="reply-tel-link" href="tel:14085551324">call</a>
<span class="reply-tel-text">call</span>
or
<a class="reply-tel-link" href="sms:14055651324">text</a>
<span class="reply-tel-text">text:</span>
</h1>
<p class="reply-tel-number">
☎ (408) 555-5678
</p>
</li>
<li class="reply-email">
<h1>reply by email:</h1>
</li>
<li>
<h1>webmail links:</h1>
<ul class="reply-emails">
<li>
<p>
</p>
</li>
<li>
<p>
</p>
</li>
<li>
<p>
</p>
</li>
<li>
<p>
</p>
</li>
</ul>
</li>
<li>
<h1>copy and paste into your email:</h1>
<p class="anonemail"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcbfb6bbb1a6f1eae8e4e8efefebeafbfba98b9acfafbaba3e48499">[email protected]</a></p>
</li>
</ul>
</aside>
I need to extract the contact name from this HTML code. However, sometimes the contact name is empty and in those cases, I get the email address instead. In such instances, the output should be blank when the name is not found. I am currently using the following code:
name = driver.switchTo().window(child_window).findElement(By.cssSelector("aside.reply-flap.js-captcha ul > li:nth-child(1) p")).getText();
I am aware that if I were using Jsoup, I could use "contains(contact name:)". How can I achieve a similar functionality in Selenium?
I have tried something like
h1[contains(text()='contact name:')]
but it is not working at all.