Below is the html code
<h2 id="xyz" class="test">
<button class="restore 1" value="test2" title="hello"> Line1 </button>
<button class="restore 2" value="test3" title="click"> Line2 </button>
I need this text
</h2>
I need to extract the text "I need this text" from the above code.
I tried by the following ways but could not get the only line "I need this text:
1.) By.xpath("//h2[@id='xyz']").gettext(); getting error saying InvalidSelectorError: The result of the xpath expression "//h2[@id='xyz']/following-sibling::text()" is: [object Text]. It should be an element.
2.) By.xpath("//h2[@id='xyz']").getattribute(innerText); By this selector i am getting the output as line1,line2 & I need this text
My expected output should only be "I need this text"