gpt4 book ai didi

c# - 字段从未分配警告,使用 Webdriver PageFactory

转载 作者:太空宇宙 更新时间:2023-11-03 11:22:45 24 4
gpt4 key购买 nike

我在 Visual Studio 2010 中收到警告消息:“从未分配字段”。我使用在运行时分配字段的 Webdriver PageFactory,如何抑制此消息?

这里是代码示例:

public class VideoInfo
{
[FindsBy(How = How.ClassName, Using = "detailsTitle")]
private IWebElement _videoInfoDetailsTitle; //Here is got the warning message

public VideoInfo(IWebDriver webDriver)
{
PageFactory.InitElements(webDriver, this); //Assigen the field
}
}

最佳答案

因为有一些编译器无法检测到的巫术;你可以忽略警告。但是,显式初始化该字段可能更好:

[FindsBy(How = How.ClassName, Using = "detailsTitle")]  
private IWebElement _videoInfoDetailsTitle = null;

关于c# - 字段从未分配警告,使用 Webdriver PageFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10409510/

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