Search code examples
c#seleniumgettext

Selenium How To Get Title Text?


<span class="Voting__button Voting__button-up">
<a href="#" title="Upvote">  ---> Need get title word in my textbox

I tried it like this:

      textbox1.text= driver.findelement(by.xpath("//*[@id='posts_list']/ul/li[1]/div/div[2]/div[2]/div[2]/span[1]/span/span/a")).Text;

I want to get this title but it’s not working.


Solution

  • As you supplied C# tag, the method() is not findelement() but FindElement().

    So, as per the HTML you have provided to extract the title value Upvote you can use the following line of code :

    textbox1 = driver.FindElement(By.XPath("//*[@id='posts_list']//span[@class='Voting__button Voting__button-up']/a")).GetAttribute("title");