I am converting a old Selenium/C# test suite to Playwright/C# and it is going very well apart from one little issue, which is....
In the Selenium suite this code correctly returns the value from a text box
var tValue = Driver.FindElement(locator).GetDomProperty("value") ?? "";
However this code in the new Playwright suite when running the same test returns nothing
var tValue = await locator.GetAttributeAsync("value") ?? "";
This works fine for these attributes, only the attribute value is failing although it works in Selenium version.
tValue = await locator.GetAttributeAsync("type") ?? "";
tValue = await locator.GetAttributeAsync("class") ?? "";
tValue = await locator.GetAttributeAsync("id") ?? "";
Any ideas please
GetAttributeAsync("value")
fetches the initial HTML attribute, not the current input value. For dynamic values (like text typed by users), use:csharp var tValue = await locator.InputValueAsync();
This mirrors the behavior ofGetDomProperty("value")
in Selenium.