Is it possible to get text only from the parent element and not its children in Selenium?
Example: Suppose I have the following code:
<div class="linksSection> <a href="https://www.google.com/" id="google">Google Link <span class="helpText">This link will take you to Google home page.</span> </a> ... </div>
In C # (or any other language) I will have:
string linktext = driver.FindElement(By.CssSelector(".linksSection > a#google")).Text; Assert.AreEqual(linkText, "Google Link", "Google Link fails text test.");
However, in the linktext there will be a link "Google LinkThis" will lead you to the Google homepage.
Without doing a lot of string manipulation (for example, getting the text of all the children and subtracting the parent from the resulting text), is there a way to get only the text from the parent?
c # selenium selenium-webdriver
Machtyn
source share