0

I am trying to get text from all the threads in a chat, and they are of same name.I Intend to put them all in a txt doc. e.g

<div data-tid="message" dir="auto"><div>Text1</div></div>
.....
<div data-tid="message" dir="auto"><div>Text2</div></div>

I am trying to use a loop to get text from all divs, but cannot get attribute within loop.

IReadOnlyCollection<IWebElement> chatRow = driver.FindElement(By.XPath("//*[@data-tid='message']/div"));
for (int i = 0; i < chatRow.Count; i++)
{
    GetAttribute("innerHTML");
}

Is there a way a do it without a loop? or how to get attributes from within the loop?

1 Answer 1

1

The problem is you are using FindElement instead of FindElements

Replace

IReadOnlyCollection<IWebElement> chatRow = driver.FindElement(By.XPath("//*[@data-tid='message']/div"));

With

IReadOnlyCollection<IWebElement> chatRow = driver.FindElements(By.XPath("//*[@data-tid='message']/div"));
for (int i = 0; i < chatRow.Count; i++)
{
    chatRow.ElementAt(i).GetAttribute("innerHTML");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.