Question

In Watin script I want to attach to another browser with the condition - "handle of new IE is not equal to handle of current IE", here is my code:

var hwnd = currentIE.hWnd;
var newIE= Browser.AttachTo<IE>(Find.By("hwnd", handle => !handle.Equals(hwnd)  ));

There is a warning from Visual Studio:

"suspicious comparison: there is no type in the solution which is inherited from both 'string' and 'System.IntPtr'

What's wrong here?

Was it helpful?

Solution

I don't know what Watin is, but evidently handle and hwnd have different types (string and IntPtr), and there is no point to comparing them with Equals.

Whichever one is a string, you can try converting it to an IntPtr:

static IntPtr ParseIntPtr (string s)
{
    s = s.Replace ("0x", "");
    return (IntPtr) int.Parse(s, System.Globalization.NumberStyles.AllowHexSpecifier);
}

(I took the method from here).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top