Selenium clicking the wrong item

I have some tests. Sometimes, if an item cannot be found, it simply presses the top left of the screen. This does not always happen, but it does. I do not know why this is happening. In my setUp method, I say to click the Maximize element, however, if it cannot find this element, I put it in catch and ignore it. For some reason, when he cannot find the item, he simply clicks on the upper left corner of the screen on which there is an application session.

Does anyone have any idea why this is happening, or is it just how selenium sometimes reacts

My code is as follows

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 { 

This is an element that I have a problem with ignoring if it does not exist

  webDriverWait.Until(ExpectedConditions.ElementTo‌​BeClickable(excelSession.FindElementByName("Maximize"))).Click(); } catch (Exception) { //ignore } 
+5
source share
1 answer

First you can try to get the current window handler, and then try to find and get the Webelement element that points to the Maximize button for the window. You may also need to simply wait for a WebElement search to be safe.

This api can be useful for C # client for selenium-driver.SwitchTo (). Window (handle)

And for details you can check here

0
source

Source: https://habr.com/ru/post/1270490/


All Articles