From e323d3aea1ef661b609c36b4bc9e01f1c66d2f99 Mon Sep 17 00:00:00 2001 From: Jens Linkekamp Date: Mon, 8 Nov 2021 16:54:00 +0100 Subject: [PATCH] Fixed Grid.OpenRecord() --- .../DTO/AppElementReference.cs | 22 +++++++++---------- .../WebClient.cs | 20 +++++------------ 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/Microsoft.Dynamics365.UIAutomation.Api.UCI/DTO/AppElementReference.cs b/Microsoft.Dynamics365.UIAutomation.Api.UCI/DTO/AppElementReference.cs index 7cc1ae8d..49eba89b 100644 --- a/Microsoft.Dynamics365.UIAutomation.Api.UCI/DTO/AppElementReference.cs +++ b/Microsoft.Dynamics365.UIAutomation.Api.UCI/DTO/AppElementReference.cs @@ -398,25 +398,25 @@ public static class AppElements //Grid { "Grid_Container" , "//div[@data-id='data-set-body-container']"}, - { "Grid_PCFContainer" , "//div[@ref='eViewport']"}, + { "Grid_PCFContainer" , "//div[@data-id='entity_control_container']"}, { "Grid_QuickFind" , "//*[contains(@id, \'quickFind_text\')]"}, - { "Grid_NextPage" , "//button[contains(@data-id,'moveToNextPage')]"}, - { "Grid_PreviousPage" , "//button[contains(@data-id,'moveToPreviousPage')]"}, - { "Grid_FirstPage" , "//button[contains(@data-id,'loadFirstPage')]"}, - { "Grid_SelectAll" , "//button[contains(@title,'Select All')]"}, - { "Grid_ShowChart" , "//button[contains(@aria-label,'Show Chart')]"}, + { "Grid_NextPage" , "//button[contains(@id,'nextPage')]"}, + { "Grid_PreviousPage" , "//button[contains(@id,'previousPage')]"}, + { "Grid_FirstPage" , "//button[contains(@id,'firstPage')]"}, + { "Grid_SelectAll" , "//button[contains(@class, 'cc-ds-header-select-all-btn')]"}, + { "Grid_ShowChart" , "//button[@id='ShowChartPane-button']"}, { "Grid_JumpBar" , "//*[@id=\"JumpBarItemsList\"]"}, { "Grid_FilterByAll" , "//*[@id=\"All_link\"]"}, { "Grid_RowsContainerCheckbox" , "//div[@role='checkbox']" }, { "Grid_RowsContainer" , "//div[contains(@role,'grid')]"}, - { "Grid_Rows" , "//div[@ref='centerContainer']//div[@role='rowgroup']//div[contains(@role,'row')]"}, - { "Grid_Row" , "//div[@data-id='entity_control-pcf_grid_control_container']//div[@ref='centerContainer']//div[@role='rowgroup']//div[@row-index=\'[INDEX]\']"}, - { "Grid_LastRow" , "//div[@data-id='entity_control-pcf_grid_control_container']//div[@ref='centerContainer']//div[@role='rowgroup']//div[contains(@class, 'ag last-row')]"}, + { "Grid_Rows" , "//div[@data-id='entity_control_container']//div[@role='grid']//div[contains(@role,'row')]"}, + { "Grid_Row" , "//div[@data-id='entity_control_container']//div[@role='grid']//div[@aria-rowindex=\'[INDEX]\']"}, + { "Grid_LastRow" , "//div[@data-id='entity_control_container']//div[@role='grid']//div[contains(@class, 'ag last-row')]"}, { "Grid_Control", "//div[contains(@data-lp-id, 'MscrmControls.Grid.PCFGridControl')]" }, { "Grid_Columns" , "//div[contains(@ref,'eHeaderContainer')]"}, { "Grid_ChartSelector" , "//span[contains(@id,'ChartSelector')]"}, { "Grid_ChartViewList" , "//ul[contains(@role,'listbox')]"}, - { "Grid_SortColumn", "//div[contains(@ref,'eHeaderContainer')]//label[@title='[COLNAME]']"}, + { "Grid_SortColumn", "//div[contains(@class,'colheaders')]//div[@title='[COLNAME]']"}, { "Grid_Cells", ".//div[@role='gridcell']"}, { "Grid_CellContainer" ,"//div[@role='grid'][@data-id='grid-cell-container']"}, { "Grid_ViewSelector" , "//button[contains(@id,'ViewSelector')]" }, @@ -469,7 +469,7 @@ public static class AppElements { "Entity_SubGrid_Row" , "//div[@ref='centerContainer']//div[@role='rowgroup']//div[@row-index=\'[INDEX]\']"}, { "Entity_SubGrid_LastRow" , "//div[@ref='centerContainer']//div[@role='rowgroup']//div[contains(@class, 'ag-row-last')]"}, { "Entity_SubGridTitle", "//div[contains(text(), '[NAME]')]" }, - { "Entity_SubGridContents", "//div[@id=\"dataSetRoot_[NAME]\"]" }, + { "Entity_SubGridContents", "//div[@data-id='dataSetRoot_[NAME]']" }, { "Entity_SubGridList", "//div[@data-id='[NAME]-pcf_grid_control_container']//div[@ref='centerContainer']//div[@role='rowgroup']//div[@role='row']" }, { "Entity_SubGridListCells", ".//div[@class='ag-center-cols-viewport']//div[@role='rowgroup']" }, { "Entity_SubGridViewPickerButton", ".//span[contains(@id, 'ViewSelector') and contains(@id, 'button')]" }, diff --git a/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs b/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs index 20e453a3..d9866fc0 100644 --- a/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs +++ b/Microsoft.Dynamics365.UIAutomation.Api.UCI/WebClient.cs @@ -1548,14 +1548,14 @@ internal BrowserCommandResult OpenRecord(int index, int thinkTime = Consta int lastRowInCurrentView = 0; while (!lastRow) { - if (!driver.HasElement(By.XPath(AppElements.Xpath[AppReference.Grid.Row].Replace("[INDEX]", (index).ToString())))) + if (!driver.HasElement(By.XPath(AppElements.Xpath[AppReference.Grid.Row].Replace("[INDEX]", (index+2).ToString())))) { lastRowInCurrentView = ClickGridAndPageDown(driver, grid, lastRowInCurrentView); } else { gridRow = driver.FindElement(By.XPath - (AppElements.Xpath[AppReference.Grid.Row].Replace("[INDEX]", index.ToString()))); + (AppElements.Xpath[AppReference.Grid.Row].Replace("[INDEX]", (index+2).ToString()))); lastRow = true; } if (driver.HasElement(By.XPath(AppElements.Xpath[AppReference.Grid.LastRow]))) @@ -1564,8 +1564,8 @@ internal BrowserCommandResult OpenRecord(int index, int thinkTime = Consta } } if (gridRow == null) throw new NotFoundException($"Grid Row {index} not found."); - var xpathToGrid = By.XPath("//div[contains(@data-lp-id,'MscrmControls.Grid')]"); - var gridContainer = driver.FindElement(By.XPath("//div[contains(@data-lp-id,'MscrmControls.Grid')]")); + var xpathToGrid = By.XPath("//div[contains(@class,'MscrmControls.Grid')]"); + var gridContainer = driver.FindElement(By.XPath("//div[contains(@class,'MscrmControls.Grid')]")); IWebElement control = driver.WaitUntilAvailable(xpathToGrid); Func action; @@ -1574,16 +1574,8 @@ internal BrowserCommandResult OpenRecord(int index, int thinkTime = Consta else action = e => e.DoubleClick(); - var xpathToCell = By.XPath(AppElements.Xpath[AppReference.Grid.Row].Replace("[INDEX]", index.ToString())); - control.WaitUntilClickable(xpathToCell, - cell => - { - var emptyDiv = cell.FindElement(By.TagName("div")); - //driver.Perform(action, cell, cell.LeftTo(emptyDiv)); - driver.Perform(action, cell, null); - }, - $"An error occur trying to open the record at position {index}" - ); + var xpathToCell = By.XPath(AppElements.Xpath[AppReference.Grid.Row].Replace("[INDEX]", (index + 2).ToString()) + "//div[@aria-colindex='2']"); + driver.Perform(action, driver.FindElement(xpathToCell)); driver.WaitForTransaction(); return true;