hi i done some research and find out the way to get browser URL using AccessibleObjectFromPoint or by this you can access any UI element so please tell me whats wrong in my code
ERROR:- **** GETTING ChildID = 0 EVERY TIME DONT KNOW WHY *******
Process[] processes = Process.GetProcessesByName("chrome");
foreach (Process p in processes)
{
IntPtr windowHandle = p.MainWindowHandle;
Rectangle rect = new Rectangle();
GetWindowRect(windowHandle, out rect);
//System.Windows.Forms.MessageBox.Show("Top = " + rect.Top + "left = " + rect.Left + "width = " + rect.Width + "height = " + rect.Height + "X = " + rect.X + "Y = " + rect.Y + "Right = " + rect.Right + "Bottom = " + rect.Bottom);
System.Drawing.Point pt = new System.Drawing.Point();
if (rect.Width > 20 && rect.Height > 20)
{
pt.X = rect.Left + ((rect.Right - rect.Left) / 4); // point in the middle
pt.Y = rect.Top + 30; // and a little bit lower (URL edit field)
int try_again_cnt = 0;
try_again:
pt.Y += 4;
if (try_again_cnt++ > 6)
return;
object varChildID;
IAccessible accObj;
IntPtr success = AccessibleObjectFromPoint(pt, out accObj, out varChildID);
int ChildID = (int)varChildID;
**** GETTING ChildID 0 EVERY TIME DONT KNOW WHY *******
if (ChildID != 0)
{
string s = accObj.get_accValue(varChildID);
System.Windows.MessageBox.Show(s);
}
else
{
goto try_again;
}
}