How to get parent element text and remove child element text selenium c#?

As per the HTML you have provided to extract the text Text1 you can use the following code block:

IWebElement myElem = driver.FindElement(By.XPath("//div[@class='item-title list-friend-conctact__title has-status']"));
string myText = (string)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].firstChild.textContent;", myElem);

Comments

  1. Israel

    • 2016/5/7

    i'm a newbie of automation testing, now i'm using selenium C#. I have a problem, i want to get text from a element, but the code :

  2. Lennox

    • 2019/6/4

    As per the HTML you have provided to extract the text Text1 you can use the following code block: IWebElement myElem = driver.FindElement(By.XPath("//div[@class='item-title list-friend-conctact__title has-status']")); string myText = (string)((IJavaScriptExecutor)driver).ExecuteScript("return arguments[0].firstChild.textContent;", myElem);

  3. Gregory

    • 2019/1/12

    Python answers related to “selenium get parent element”. how to access parent class attribute from child class in python · python selenium get child element 

  4. Alonzo

    • 2020/2/18

    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. get the parent element's text, for each child, get the text and remove it from the parent's text. What you would have left is the desired text - Google Link in your case.

  5. Grasso

    • 2019/5/6

    You can remove the child node text from the all text all_text To get the own text of an element in a safe manner, you have to iterate over the children 

  6. Gatlin

    • 2020/8/19

    get the parent element's text, for each child, get the text and remove it from the parent's text. What you would have left is the desired text - Google Link in your case. if you want to get the Google Link just to make an assertion, it could be that you would be okay with checking if the parent's text s tarts with Google Link .

  7. Marku

    • 2020/6/11

    to select text from a child node and current node at onceHow to get parent element text and remove child element text selenium c#?.

  8. Kohen

    • 2017/7/30

    We can identify the child nodes from the parent, by localizing it with the parent and then passing ( ./child::*) as a parameter to the findElements(By.xpath()) Syntax−. parent.findElements(By.xpath("./child::*")) Let us identify the text of the child nodes of ul node in below html code−. Example

  9. Westin

    • 2020/7/9

    We can locate child nodes of web elements with Selenium webdriver. for ( WebElement i : c ) { //getText() to get text for child nodes 

  10. Harrison

    • 2021/3/16

    Select parent element of known element in Selenium, you want to find the data-tooltip's text from the div.select-container for <select name="day">' only. Here's how you do that in Java with xpath's Selenium get the parent of an element. You might run a in a situation when you selected an element and you need to get it’s parent .

  11. Vincent

    • 2019/8/13

    So lets see one code that would print all the text but here it will go first to parent and then it would go to child element. import java.util.List; import org.

  12. Emir

    • 2017/5/30

    Remove XML Parent Elements Based on Condition of Child Element – Python I am attempting to remove parent XML elements based on the text of specific child elements containing values of “nan”. The input XML contains namespaces which is making this trickier than expected and I can remove select child elements individually, but not the

  13. Drew

    • 2021/4/26

    Siblings refer to child elements having the same parent. To get to the <td> we wish to access (the one with the text “fourth cell”), 

  14. D'Angelo

    • 2021/7/9

    Getting text or attributes of elements (e.g. Get Element Text and Get elements, parent/child xpath will match all these child elements.

  15. Aidan

    • 2020/4/12

    The getElementsByClassName method of Document interface returns an array-like object of all child elements which have all of the given class 

  16. Williams

    • 2019/7/17

    It returns a boolean value of the result. This method is used on the parent element and the parameter passed in the method is the child element 

Comments are closed.

Recent Posts