Jump to content

Direct text field selection in Chrome/Explorer/etc.


Will0674
 Share

Recommended Posts

Hello everyone! I'm new to the forum (and AutoIT, for that matter), and I am currently developing a script to extract constantly refreshing text from a search engine\web location (preferably Chrome). I am attempting to check Apple's stock on a regular basis, copy the info and analyze it within Excel. I am relatively proficient with Excel/VBA macros, but AutoIT seems to be a little happier about exploring outside of Excel, so it doesn't do me much good :). My current predicament is I cannot *directly* select a given text box within the site itself- so far, I can only accomplish the task by either:

-invoking the appropriate amount of Send("+{TAB}")/Send("{TAB}") commands to locate it (don't judge me, ha ha! ;))

-Using MouseClick to find the box (however, this seems to be hit or miss, coordinate wise (and it's slow).

Using MouseClick seems to take a while, and it's still hard to decipher which coordinates to use. Regardless, I would love to NOT use it, I want to be able to perform this action quickly and decisively, as opposed to "hoping" the coordinates are in the right place. Is there some control in the Window Info viewer I am missing? I can only seem to activate the actual browser URL address window, but no other text entry boxes. Let me know if you guys have encountered what I am attempting to create, and anything that can point me in the right direction. Thank you!!

Link to comment
Share on other sites

  • Moderators
Hi, Will0674, welcome to the forum. Are you able to include the site you're wanting to pull the data from? Each site seems to handle things differently (Yahoo! Finance and Marketwatch, for example). If you have a particular page you're trying to script for, it'll help greatly :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thanks! Well for now, I have just been using Yahoo finance, since it displays the information in a relatively organized fashion when clipboarded and pasted into Excel. Those values themselves might have to be collected using the coordinate plane, since they are effectively streaming values. I just need I be able to activate the search box so I can specify (quickly) look at company X or Y, then compare the data. Thank you for your help!

Link to comment
Share on other sites

You should also check out AutoIts Internet Explorer automation functions => #include <IE.au3>

You can find all the info from auto it helpfile. You could use the IE for example

1. Open the Yahoo finance page invisible into the background.

2. Use IE functions to fetch spesific contect from page. (You can search through DOM)

3. Use Excel automation UDF to paste the data to excel, also invisible in background.

This way you can keep on working with your computer while the script does the data fetching for you in the background.

Here is example:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

; Function for collecting data from Yahoo finance and pasting it to Excel
#region - INCLUDES & CONSTANTS

#include <IE.au3>
#include <Excel.au3>

Global $oIE, $sData, $oExcel

#endregion - INCLUDES & CONSTANTS

$oIE = _IECreate("http://finance.yahoo.com/q?s=AAPL&ql=1") ; check out the parameters to set IE and Excel invisible
$oExcel = _ExcelBookNew()

While 1

$sData = $oIE.document.getElementById("yfs_l91_aapl").innerText
If $sData Then
  _ExcelWriteCell($oExcel, $sData, 1, 1)
EndIf
$sData = ""
Sleep(5 * 60 * 1000) ; sleeps for 5 min before checks again.

_IENavigate($oIE, "http://finance.yahoo.com/q?s=AAPL&ql=1")

WEnd

This way you can also get rid of using mouse clicks and tabs which are unreliable way to get data from websites.

Edited by Eemuli
Link to comment
Share on other sites

That's outstanding, I'll give that a try tomorrow- thanks! As much as I hate IE, i guess i can put up with it :)

I used to hate IE too, but then I found out how easy it is to automate through COM object ;)

Also the new IE 9 works very well and looks good.

Link to comment
Share on other sites

Also the new IE 9 works very well and looks good.

You won't be saying that about IE10 unless MS comes to thier senses.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • 3 years later...

Hi,

I am new to AutoIt. Looks like my requirement matches more or less above requirement. I need to read a text from a text box which is in chrome/IE (browser). In the above example, you have given the elementId of text to read the text data but in my case I don' know how to find the "element Id" of my text box? Is there anyway to find it?

 

Thanks,

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...