Get parent element text without children's text
Date : March 29 2020, 07:55 AM
|
jQuery - get only parent element text without children
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You could filter away everything that is not plain text by looping all contents: var node = $('.someParentDiv > span').contents().filter(function() {
return this.nodeType == 3; // text node
});
alert(node.text());
|
How to get text from parent element and exclude text from children (C# Selenium)
Tag : chash , By : arbeitandy
Date : March 29 2020, 07:55 AM
Any of those help This is a common problem in selenium since you cannot directly access text nodes - in other words, your XPath expressions and CSS selectors have to point to an actual element. Here is the list of possible solutions for your problem: string outerHTML = driver.FindElement(By.CssSelector(".linksSection > a#google")).GetAttribute("outerHTML");
HtmlDocument html = new HtmlDocument();
html.LoadHtml(outerHTML);
HtmlAgilityPack.HtmlNode a = html.DocumentNode.SelectNodes("//a[@id='google']");
HtmlNode text = strong.SelectSingleNode("following-sibling::text()");
Console.WriteLine(text.InnerText.Trim());
|
Protractor does not see the element's children
Date : March 29 2020, 07:55 AM
this one helps. element(by.css('.form-group')) returns an ElementFinder, not the DOM element you need to query its children. This works kinda slow if you have a lot of elements but does the job: var getLeafs = function(node) {
return node.all(by.css('*')).filter(function(child) {
return child.all(by.xpath('*')).count().then(function(childrenCount) {
return childrenCount === 0;
});
});
};
var leafs = getLeafs(element(by.css('.form-group')));
leafs.count().then(function(c) {
console.log(c);
});
|
How can we click on a parent element of a particular text in protractor
Date : March 29 2020, 07:55 AM
around this issue Our UI code is given below. , Short answer let h4ByText = (text) => element(by.xpath(`//*[@class="frx-rule-body"]//h3[contains(text(),"${text}")]//ancestor::div[contains(@class,"frx-rule-block")]//h4`));
|