Selenium 从 Unicef material-ui currency TextField 获取价值
Selenium get value from Unicef material-ui currency TextField
我需要验证“Unicef material-ui 货币文本字段”中的值。
我使用波纹管代码获取文本框中的值,但该值为空。
var value = driver.FindElement(By.Id("txtCurrency")).Text;
如果您检查下面示例中的输入字段,您可以看到即使文本在视觉上显示,“value”HTML attribute 为空。
HTML快照:
HTML:
<input aria-invalid="false" type="text" class="MuiInputBase-input MuiOutlinedInput-input jss493 jss561 MuiInputBase-inputAdornedStart MuiOutlinedInput-inputAdornedStart" value="">
示例 URL 如下:https://unicef.github.io/material-ui-currency-textfield/#currencytextfield
我想知道一种获取输入文本框 value/text 的方法。
项目在 ReactJs 中,Selenium 在 C# 中
要从 input 字段中获取 value,您需要使用 .GetAttribute("value")
使用以下 xpath
来识别元素。
var Value =driver.FindElement(By.XPath("//h6[text()='Outlined']/following::input[1]")).GetAttribute("value");
Console.WriteLine(Value);
或关注css selector
var Value =driver.FindElement(By.CssSelector(".MuiInputBase-input.MuiOutlinedInput-input.jss134.jss202.MuiInputBase-inputAdornedStart.MuiOutlinedInput-inputAdornedStart")).GetAttribute("value");
Console.WriteLine(Value);
所需的元素是 ReactJS enabled element so you have to induce WebDriverWait for the desired ElementToBeClickable()
and you can use either of the following :
XPath 和 GetAttribute("value")
:
Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//h6[text()='Outlined']//following::div//input[contains(@class, 'MuiInputBase-input')]"))).GetAttribute("value"));
我需要验证“Unicef material-ui 货币文本字段”中的值。 我使用波纹管代码获取文本框中的值,但该值为空。
var value = driver.FindElement(By.Id("txtCurrency")).Text;
如果您检查下面示例中的输入字段,您可以看到即使文本在视觉上显示,“value”HTML attribute 为空。
HTML快照:
HTML:
<input aria-invalid="false" type="text" class="MuiInputBase-input MuiOutlinedInput-input jss493 jss561 MuiInputBase-inputAdornedStart MuiOutlinedInput-inputAdornedStart" value="">
示例 URL 如下:https://unicef.github.io/material-ui-currency-textfield/#currencytextfield 我想知道一种获取输入文本框 value/text 的方法。
项目在 ReactJs 中,Selenium 在 C# 中
要从 input 字段中获取 value,您需要使用 .GetAttribute("value")
使用以下 xpath
来识别元素。
var Value =driver.FindElement(By.XPath("//h6[text()='Outlined']/following::input[1]")).GetAttribute("value");
Console.WriteLine(Value);
或关注css selector
var Value =driver.FindElement(By.CssSelector(".MuiInputBase-input.MuiOutlinedInput-input.jss134.jss202.MuiInputBase-inputAdornedStart.MuiOutlinedInput-inputAdornedStart")).GetAttribute("value");
Console.WriteLine(Value);
所需的元素是 ReactJS enabled element so you have to induce WebDriverWait for the desired ElementToBeClickable()
and you can use either of the following
XPath 和
GetAttribute("value")
:Console.WriteLine(new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//h6[text()='Outlined']//following::div//input[contains(@class, 'MuiInputBase-input')]"))).GetAttribute("value"));