Selenium:从电子邮件中获取字符串 textfield/textbox
Selenium: Get the string out of a email textfield/textbox
我想从最近输入的电子邮件文本框中获取电子邮件字符串。
我正在使用 selenium 进行自动化测试并确认文本框中输入了正确的字符串,我想在进入密码文本框之前重新检查它。
我在这里看到了很多示例,但最多的是 getText();
(似乎不再有效)或 getAttribute("Value");
。
我调试了一下,checkText
总是给出Null。
我目前拥有的是这段代码:
public static void SendKeysElement(IWebDriver webDriver)
{
IWebElement Field = webDriver.FindElement(By.XPath(selector));
Field.SendKeys("example@example.com");
string checkText = Field.GetAttribute("Value");
if (checkText != "example@example.com")
{
Console.WriteLine("String is wrong");
}
else
{
ConsoleWriteLine("String is correct");
}
}
这是输入电子邮件字符串时对该文本框的检查。
我注意到的第一件事是,在电子邮件文本框中输入的字符串没有显示在检查中。
正在使用 .NET 使用 blazor 模板编写网页。
而不是
.GetAttribute("Value")
试试这个:
.GetAttribute("value");
请注意,属性类型区分大小写。
我想从最近输入的电子邮件文本框中获取电子邮件字符串。
我正在使用 selenium 进行自动化测试并确认文本框中输入了正确的字符串,我想在进入密码文本框之前重新检查它。
我在这里看到了很多示例,但最多的是 getText();
(似乎不再有效)或 getAttribute("Value");
。
我调试了一下,checkText
总是给出Null。
我目前拥有的是这段代码:
public static void SendKeysElement(IWebDriver webDriver)
{
IWebElement Field = webDriver.FindElement(By.XPath(selector));
Field.SendKeys("example@example.com");
string checkText = Field.GetAttribute("Value");
if (checkText != "example@example.com")
{
Console.WriteLine("String is wrong");
}
else
{
ConsoleWriteLine("String is correct");
}
}
这是输入电子邮件字符串时对该文本框的检查。 我注意到的第一件事是,在电子邮件文本框中输入的字符串没有显示在检查中。
正在使用 .NET 使用 blazor 模板编写网页。
而不是
.GetAttribute("Value")
试试这个:
.GetAttribute("value");
请注意,属性类型区分大小写。