Search code examples
c#seleniumxpathyahoo-mail

Unable to get value of subject field of the draft using Webdriver in Yahoo draft mail


I've created draft letter in Yahoo mail and then get to this draft letter page. Now I'd like to get value of the Subject field using C# and Selenium Webdriver. I used the following code, but it returns empty string :

string subjectLocator = "//*[@id='subject-field']";
string actualSubject = driver.FindElement(By.XPath(subjectLocator)).GetAttribute("Value");

Using of Text property instead of GetAttribute method also doesn't help.

How to get value of the subject field in yahoo draft letter using Selenium Webdriver and C#?

http://prnt.sc/bye5ae - html code


Solution

  • As I seeing you are using to get value from subject field as .GetAttribute("Value"), here only problem is to passing attribute property as Value which should be value means v should be in lowercase, So you should try as below :-

    string actualSubject = driver.FindElement(By.Id("subject-field")).GetAttribute("value");
    

    Or using WebDriverWait to wait until element present on DOM as below :

    var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    IWebElement element = wait.Until(ExpectedConditions.ElementExists(By.Id("subject-field")));
    string actualSubject = element.GetAttribute("value");
    

    I have tested it and it works for me.

    Hope it helps...:)