appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
385 stars 187 forks source link

Client fails to return correct element attribute value #398

Closed saulius453 closed 3 years ago

saulius453 commented 4 years ago

Description

In my tests I want to enter some text into input box and then read it to make sure that input method succeeded. So in my code I use element.SendKeys(value); and then I read it var commentText = element.Text; I expect that read text would be the same as inputed text. But its not! Before entering text into input box, box has prefilled value "Add comment". I enter the new text (this deletes the old text), read the element text and still get the old value "Add comment" but if I extract the PageSource "Add comment" text is not present anymore (my new entered text is present).

Environment

Code To Reproduce Issue

Before writing anything read the PageSource. Result: <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="Add comment" name="payment_attachments_comment_input" label="" enabled="true" visible="true" x="75" y="512" width="200" height="48"/> Using PageObject model write text into element like this: element.SendKeys(value); Read the PageSource again. Result: <XCUIElementTypeTextField type="XCUIElementTypeTextField" value="Test!!!😎" name="payment_attachments_comment_input" label="" enabled="true" visible="true" x="75" y="512" width="200" height="48"/> Now read it like this: var commentText = element.Text; Or like this: var commentText = element.GetAttribute("value"); The read result is "Add comment".

mykola-mokhnach commented 4 years ago

Duplicate of https://github.com/appium/appium/issues/13691

saulius453 commented 4 years ago

My workaround for this issue:

var pageSource = Driver.Instance.PageSource;
Regex regex = new Regex("value=\"(.*?)\"");
var matches = regex.Matches(pageSource);
foreach (Match m in matches)
{
    var elementText = m.Groups[1].ToString();
    if (elementText.Contains(value))
    {
        commentText = elementText;
        break;
    }
}

Where value is the text I enter into the input box and commentText the real value that is read from Page Source.