Retrieving Text between Text in Selenium C#

前端 未结 6 1375
走了就别回头了
走了就别回头了 2020-12-19 06:38

I am facing problem in retrieving Subject title of a mail from Unread mails using Selenium webdriver-C#.

Here\'s the HTML code :

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-19 06:53

    Probably too late but could be helpful for someone.

            IWebElement spanText= driver.FindElement(By.XPath("//span[contains(text(), 'TEXT TO LOOK FOR')]"));
            spanText.Click();
    
    
            IWebElement spanParent= driver.FindElement(By.XPath("//span[contains(text(), 'TEXT TO LOOK FOR')]/ancestor::li"));
            spanParent.FindElement(By.XPath(".//a[contains(text(), 'SIBLING LINK TEXT')]")).Click();
    

    bonus content here to look for siblings of this text once the span element is found, look for siblings by starting from parent. I am looking for an anchor link here. The dot at the start of XPath means you start looking from the element spanParent

  • TEXT TO LOOK FOR SIBLING LINK TEXT
提交回复
热议问题