Search code examples
c#seleniumselenium-webdriverpageobjectsfindby

How to retrieve value from the below given tags


This is from one of our web application. I want to retrieve value 8 to compare it against value from database.

[FindsBy(How = How.Id, Using = "p_Power Reactors_planned")]
public IWebElement Planned_PR { get; set; }

string PRPlanned = Planned_PR.GetAttribute("p");

HTML:

<p class="big" id="p_Power Reactors_planned">8</p>

I am getting empty result string.


Solution

  • You are using wrong command to retrieve the text

    GetAttribute(); is used to retrieve the value of attribute of an HTML tag

    e.g. <p class="big" id="p_Power Reactors_planned">

    GetAttribute("class"); - You will get value big

    GetAttribute("id"); - You will get value p_Power Reactors_planned

    You have to use .Text method to get required text

    e.g string PRPlanned = Planned_PR.Text;

    As per HTML rule if your element fall under given tags here then you can use GetAttribute("value");