gpt4 book ai didi

c# - 使用 Selenium WebDriver 验证文本字段不为空

转载 作者:行者123 更新时间:2023-11-30 20:50:25 26 4
gpt4 key购买 nike

假设我想在继续点击提交按钮之前验证ID为“text_input”的文本输入字段不为空(包含文本),例如:

// verify that html element id "text_input" is not null

var button_Save = Driver.Instance.FindElement(By.Id("submit"));
button_Save.Click();

怎么能做到这一点?

我要验证的元素不为空的 HTML 是:

<input name="text_input" value="Fred" id="text_input" tabindex="6" class="label" type="text">

最佳答案

如果你有这样的输入:

<input name="text_input" value="Fred" id="text_input" tabindex="6" class="label" type="text">

然后您可以使用element.GetAttribute("value") 来获取它的值。来源here .

var text_input = Driver.Instance.FindElement(By.Id("text_input"));
if (!String.IsNullOrEmpty(text_input.GetAttribute("value"))) {
var button_Save = Driver.Instance.FindElement(By.Id("submit"));
button_Save.Click();
} else {
// if you want to do something
}

关于c# - 使用 Selenium WebDriver 验证文本字段不为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22597184/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com