我已经使用硒进行了许多测试。我在Visual Studio 2015中创建了解决方案,所有测试都可以运行良好,但是当我在Visual Studio 2017中进行测试时,我的所有测试都可以右键单击。
。我不确定为什么这仅在Visual Studio 2017
中发生我遇到一个运行时错误,说该元素是无效的,但是在我尝试之前的行之前,我可以单击元素,以便我知道该元素不是null。
我的代码如下
var webDriverWait = new WebDriverWait(session, TimeSpan.FromSeconds(10));
Actions action = new Actions(session);
CommonMethods.switchWindows(session);
CommonMethods.keyCheck(session);
Thread.Sleep(2000);
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(session.FindElementByName($"{fileName} - PowerPoint"))).Click();
Thread.Sleep(2000);
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(session.FindElementByName("Create"))).Click();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(session.FindElementByName("View Links"))).Click();
CommonMethods.IsElementDisplayed(session, new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod(), "CreateErrorIcon", "Error appeard when selecting the View Links button");
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(session.FindElementByName("Create"))).Click();
var e =webDriverWait.Until(ExpectedConditions.ElementToBeClickable(session.FindElementByName(SlideNumber)));
e.Click();
action.ContextClick(e).Perform();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(session.FindElementByName(element))).Click();
keyCheck(session);
我发现了问题。由于某种原因,最新版本的WinappDriver(2017年5月)不会单击上下文。下载2017年3月版本,并解决问题