0

I am new to c# and automation.I am trying to automate a process in an app. I found automation id of an element using inspect.exe and tried the following code to click the element

public void import_Enc(string excelPath, string fileName, string impConfig, 
                       string[] ImportEnclosures, Window mainwindow)
{
    SearchCriteria search1 = SearchCriteria.ByAutomationId("Libraries");
    Button button = (Button)mainwindow.Get(search1);
    button.Click();           
    importEnclosure(excelPath, fileName, impConfig, ImportEnclosures);
}

When i run the test i got an error

System.InvalidCastException: 'Unable to cast object of type 'TestStack.White.UIItems.TabItems.TabPage' to type 'TestStack.White.UIItems.Button'.'

I have tried to look for cast type of TabPage in Teststack.White but i didn't find any,do u have any idea?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
def0x
  • 1
  • 2
  • I'm not familiar with `TestStack`, but clearly, you can't cast from what `mainwindow.Get()` returned (which is `TabPage`) to `Button`. Also `Libraries` doesn't sound like a "button Id". – SᴇM Jun 10 '19 at 07:34
  • I found out `libraries` is not a "button Id" but its LocalizedControlType is given as `tab item` – def0x Jun 10 '19 at 08:09

0 Answers0