我有很多测试。有时,如果找不到元素,只需单击屏幕左上角。这不会一直发生,但确实会发生。我不确定为什么会这样。在我的 setUp 方法中,我告诉它单击元素“最大化”,但是如果它找不到该元素,我将它放入一个 catch 中并忽略它。由于某种原因,当它找不到元素时,它只是单击具有应用程序会话的屏幕左上角。
有没有人知道为什么会发生这种情况,或者硒有时会如何反应
我的代码如下
private string wordId = OfficeVersion.Word();
private string excelId = OfficeVersion.Excel();
private string powerPointId = OfficeVersion.PowerPoint();
private const string AppDriverUrl = "http://127.0.0.1:4723";
public static WindowsDriver<WindowsElement> excelSession;
public static WebDriverWait webDriverWait;
xl.Workbook WB;
public static bool skipTearDown = false;
WindowsElement create;
WindowsElement blankWorkBook;
public static DesiredCapabilities appCapabilities = new DesiredCapabilities();
[TestInitialize]
appCapabilities.SetCapability("app", excelId);
var initialSession = new WindowsDriver<WindowsElement>(new Uri(AppDriverUrl), appCapabilities);
var capabilities = new DesiredCapabilities();
capabilities.SetCapability("app", "Root");
excelSession = new WindowsDriver<WindowsElement>(new Uri(AppDriverUrl), capabilities);
webDriverWait = new WebDriverWait(excelSession, TimeSpan.FromSeconds(10));
CommonMethods.keyCheck(excelSession);
webDriverWait = new WebDriverWait(excelSession, TimeSpan.FromSeconds(10));
CommonMethods.IsElementDisplayed(excelSession, new StackTrace(true).GetFrame(0).GetFileLineNumber(), new StackTrace(true).GetFrame(0).GetMethod(), "CreateErrorIcon", "Create error when launching Excel");
try
{
如果它不存在,这是我无法忽略的元素
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(excelSession.FindElementByName("Maximize"))).Click();
}
catch (Exception)
{
//ignore
}