Thanks. Following your link, I get the following code in C#, The following function GetActiveTabIndex seems to what I need. But I do not know how to do it in python. Any ideas? Thanks.<br><a href="http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/03a8c835-e9e4-405b-8345-6c3d36bc8941">http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/03a8c835-e9e4-405b-8345-6c3d36bc8941</a><br>
<br><br><span style="color: rgb(0, 0, 255); font-size: x-small;"><span style="color: rgb(0, 0, 255); font-size: x-small;"><span style="color: rgb(43, 145, 175);"><span style="color: blue;"><span style="color: blue;"><span style="color: blue;"><p style="margin: 0px;">
<span style="color: blue;">public</span> <span style="color: blue;">int</span> GetActiveTabIndex(<span style="color: rgb(43, 145, 175);">IntPtr</span> ieHandle)</p>
<p style="margin: 0px;"> {</p>
<p style="margin: 0px;"> AccessibleObjectFromWindow(GetDirectUIHWND(ieHandle), <span style="color: rgb(43, 145, 175);">OBJID</span>.OBJID_WINDOW, <span style="color: blue;">ref</span> accessible);</p>
<p style="margin: 0px;"> <span style="color: blue;">if</span> (accessible == <span style="color: blue;">null</span>)</p>
<p style="margin: 0px;"> <span style="color: blue;">throw</span> <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">Exception</span>();</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> <span style="color: blue;">var</span> index = 0;</p>
<p style="margin: 0px;"> <span style="color: blue;">var</span> ieDirectUIHWND = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">IEAccessible</span>(ieHandle);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> <span style="color: blue;">foreach</span> (<span style="color: rgb(43, 145, 175);">IEAccessible</span> accessor <span style="color: blue;">in</span> ieDirectUIHWND.Children)</p>
<p style="margin: 0px;"> {</p>
<p style="margin: 0px;"> <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> child <span style="color: blue;">in</span> accessor.Children)</p>
<p style="margin: 0px;"> {</p>
<p style="margin: 0px;"> <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> tab <span style="color: blue;">in</span> child.Children)</p>
<p style="margin: 0px;"> {</p>
<p style="margin: 0px;"> <span style="color: blue;">object</span> tabIndex = tab.accessible.get_accState(0);</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> <span style="color: blue;">if</span> ((<span style="color: blue;">int</span>)tabIndex == IE_ACTIVE_TAB)</p>
<p style="margin: 0px;"> <span style="color: blue;">return</span> index;</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> index++; </p>
<p style="margin: 0px;"> }</p>
<p style="margin: 0px;"> }</p>
<p style="margin: 0px;"> }</p>
<p style="margin: 0px;"> </p>
<p style="margin: 0px;"> <span style="color: blue;">return</span> -1;</p>
<p style="margin: 0px;"> }</p><p style="margin: 0px;"><br></p></span></span></span></span></span></span><br clear="all">---------------------------<br>He Jibo<br>Department of Psychology,<br>Beckman Institute for Advanced Science and Technology<br>
University of Illinois, Urbana Champaign,<br>603 East Daniel St.,<br>Champaign, IL 61820<br>website: <a href="http://www.hejibo.info">www.hejibo.info</a><br><br>
<br><br><div class="gmail_quote">On Tue, Nov 30, 2010 at 4:00 PM, sharpblade <span dir="ltr"><<a href="mailto:sharpblade1@gmail.com">sharpblade1@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
This might be of some help:<div><a href="http://social.msdn.microsoft.com/forums/en-US/ieextensiondevelopment/thread/e3a501d6-2163-4cc0-be2d-5011e7fa9613/" target="_blank">http://social.msdn.microsoft.com/forums/en-US/ieextensiondevelopment/thread/e3a501d6-2163-4cc0-be2d-5011e7fa9613/</a></div>
<div><a href="http://social.msdn.microsoft.com/forums/en-US/ieextensiondevelopment/thread/e3a501d6-2163-4cc0-be2d-5011e7fa9613/" target="_blank"></a>Check out Dan Morris's post, or T E dixons.<br><br><div class="gmail_quote">
<div><div></div><div class="h5">On Tue, Nov 30, 2010 at 5:42 PM, He Jibo <span dir="ltr"><<a href="mailto:hejibo@gmail.com" target="_blank">hejibo@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">Thanks so much for your valuable information. I will only need the url of a browser when it is in the front. I am going to try SendKey, it seems to be a good way to go. Have a nice day!<div>
<br><br clear="all">---------------------------<br>
He Jibo<br>Department of Psychology,<br>Beckman Institute for Advanced Science and Technology<br>University of Illinois, Urbana Champaign,<br>603 East Daniel St.,<br>Champaign, IL 61820<br>website: <a href="http://www.hejibo.info" target="_blank">www.hejibo.info</a><br>
<br>
<br><br></div><div><div></div><div><div class="gmail_quote">On Tue, Nov 30, 2010 at 9:09 AM, Mike Driscoll <span dir="ltr"><<a href="mailto:mdriscoll@co.marshall.ia.us" target="_blank">mdriscoll@co.marshall.ia.us</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div text="#000000" bgcolor="#ffffff"><div><div></div><div>
On 1:59 PM, He Jibo wrote:
<blockquote type="cite">Hi,<br>
I am writing a small program, which needs to get the URL of the
active<br>
tab in either of firefox, internet exploerer or chrome.<br>
My need is similar as the one posted at,<br>
<a href="http://stackoverflow.com/questions/3631216/how-do-i-get-the-url-of-the-visible-tab-in-firefox-ie-chrome" target="_blank">http://stackoverflow.com/questions/3631216/how-do-i-get-the-url-of-the-visible-tab-in-firefox-<span>ie</span>-chrome</a><br>
<br>
I did a lot of Googling, and get the following code. The following<br>
code can get the url of the first tab in internet explorer. My<br>
question is, how can I get the url of the current active tab?
Thanks.<br>
<br>
'''<br>
<a href="http://efreedom.com/Question/1-2555905/Get-Internet-Explorer-Address-Bar-Python" target="_blank">http://efreedom.com/Question/1-2555905/Get-Internet-Explorer-Address-Bar-Python</a><br>
<a href="http://blogs.msdn.com/b/oldnewthing/archive/2005/07/05/435657.aspx" target="_blank">http://blogs.msdn.com/b/oldnewthing/archive/2005/07/05/435657.aspx</a><br>
<a href="http://mail.python.org/pipermail/python-win32/2004-June/002040.html" target="_blank">http://mail.python.org/pipermail/python-win32/2004-June/002040.html</a><br>
<a href="http://code.activestate.com/recipes/302324-browser-automation-tool-py-class-file/" target="_blank">http://code.activestate.com/recipes/302324-browser-automation-tool-py-class-file/</a><br>
'''<br>
from win32com.client import Dispatch<br>
import win32api, win32con,win32gui<br>
<br>
<br>
SHELL = Dispatch("Shell.Application")<br>
<br>
def get_ie(shell):<br>
for win in shell.Windows():<br>
# print win<br>
if win.Name == "Windows Internet Explorer":<br>
return win<br>
return None<br>
<br>
def main():<br>
<span>ie</span> = get_ie(SHELL)<br>
if <span>ie</span>:<br>
print <span>ie</span>.LocationURL<br>
print <span>ie</span>.LocationName<br>
print <span>ie</span>.ReadyState<br>
print <span>ie</span><br>
print <span>ie</span>.Document.title<br>
print <span>ie</span>.Document.location<br>
print <span>ie</span>.Document.forms<br>
<br>
# title = win32gui.GetWindowText(<span>ie</span>)<br>
# print title<br>
<br>
else:<br>
print "no <span>ie</span> window"<br>
<br>
if __name__ == '__main__':<br>
main()<br clear="all">
---------------------------<br>
He Jibo<br>
Department of Psychology,<br>
Beckman Institute for Advanced Science and Technology<br>
University of Illinois, Urbana Champaign,<br>
603 East Daniel St.,<br>
Champaign, IL 61820<br>
website: <a href="http://www.hejibo.info" target="_blank">www.hejibo.info</a><br>
<br>
</blockquote>
<br></div></div>
It will probably be frowned on here, but one of the easiest ways
would be to use SendKeys in combination with some Windows hackery. I
have attached some code I came up with after getting help from
several of the fine people on this list. It shows how to bring a
window into focus by just passing in an expected string. In this
case, you would want to use something like "Windows Internet
Explorer" and have it search for that.<br>
<br>
Once that's in focus, you can use the SendKeys package
(<a href="http://www.rutherfurd.net/python/sendkeys/" target="_blank">http://www.rutherfurd.net/python/sendkeys/</a>) to send an ALT+D to
select the url and then CTRL+C to copy it. Then you can use the
win32clipboard module from PyWin32 to grab the text from the
clipboard.<br>
<br>
It's a hack, but it's kind of fun. Of course, you can't use your PC
while the script runs or you might interrupt the process and send
the keys to the wrong window.<br>
<br>
<br>
<div>-- <br>
Mike Driscoll
<br>
Applications Specialist
<br>
Blog: <a href="http://blog.pythonlibrary.org" target="_blank">http://blog.pythonlibrary.org</a><br>
</div>
</div>
</blockquote></div><br>
</div></div><br></div></div>_______________________________________________<br>
python-win32 mailing list<br>
<a href="mailto:python-win32@python.org" target="_blank">python-win32@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
python-win32 mailing list<br>
<a href="mailto:python-win32@python.org">python-win32@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-win32" target="_blank">http://mail.python.org/mailman/listinfo/python-win32</a><br>
<br></blockquote></div><br>