Selenium 从联合国儿童基金会 material-ui 货币 TextField 中获取价值 [英] Selenium get value from Unicef material-ui currency TextField

查看:32
本文介绍了Selenium 从联合国儿童基金会 material-ui 货币 TextField 中获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要验证Unicef material-ui 货币文本字段"中的值.我使用波纹管代码来获取文本框中的值,但该值为空.

I need to verify a value which is in "Unicef material-ui currency textfield". I use bellow code to get the value within the textbox but the value is empty.

var value = driver.FindElement(By.Id("txtCurrency")).Text;

如果您检查以下示例中的输入字段,您可以看到即使文本以视觉方式显示,"HTML 属性为空.

If you inspect the input field in bellow sample, you can see even though text is visually displayed, "value" HTML attribute is empty.

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我想知道一种获取输入文本框的值/文本的方法.

Sample URL as bellow : https://unicef.github.io/material-ui-currency-textfield/#currencytextfield I would like to know a way to get the value/text of input textbox.

项目在 ReactJs 中,Selenium 在 C# 中

Project is in ReactJs and Selenium is in C#

推荐答案

所需的元素是一个 ReactJS 启用的元素所以你必须为所需的 ElementToBeClickable() 引入 WebDriverWait 并且你可以使用以下任一定位器策略:

The desired element is a ReactJS enabled element so you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:

  • XPathGetAttribute("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"));

这篇关于Selenium 从联合国儿童基金会 material-ui 货币 TextField 中获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆