Will0674 Posted January 7, 2012 Posted January 7, 2012 Hello everyone, I have another basic (i think) question about element locating and error messages. I am currently setting up an Excel spreadsheet to track companies' performance on Yahoo Finance. With much thanks to Eemuli for his original support, I am almost there- however, here is my problem: _IENavigate($oIE, "http://finance.yahoo.com/q?s=AAPL&ql=1") $sData = $oIE.document.getElementById("yfs_190_aapl").innerText If $sData Then _ExcelWriteCell($oExcel, $sData, 1, 1+$i) EndIf $sData = "" The variable "yfs_190_aapl" is not always available, so I need to be able to search for "yfs_191_aapl" and "yfs_l10_aapl" as well, if the first one is MIA. So my issue is terminology, really- I just need it so see if it's not there, don't kick back @error and keep moving. I have a lot of MATLAB experience, but I'm having issues translating what I want- I have tried encompassing a For loop while $sData = number, if $sData = @error Then, I just can't get it to stop having a panic attack when it's little search doesn't yield anything . And thank you again Eemuli, you've really helped out.
Robjong Posted January 7, 2012 Posted January 7, 2012 Hi, Your attemp with @error failed because the function you are using is a Javascript function, not AutoIt, so it does not set @error. If you use the _IE* functions (AutoIt) you can check @error... $oElem = _IEGetObjById($oIE, "yfs_190_aapl") If Not @error Then _ExcelWriteCell($oExcel, $oElem.innerText, 1, $i + 1) ...or you can check if the result returned by getElementById (Javascript) is an object... $oElem = $oIE.document.getElementById("yfs_190_aapl") If IsObj($oElem) Then _ExcelWriteCell($oExcel, $oElem.innerText, 1, $i + 1) I hope this clears it up.
Will0674 Posted January 7, 2012 Author Posted January 7, 2012 (edited) Interesting, I thought it was essentially a hard-coded error "function" that causes the break. That's great info, thank you! Will either of the examples you've shown allow the code to advance if either @error or no object is encountered? I guess what I'm asking is would I need to use an IfElse (forgive my MATLAB speak) afterwards to keep it moving? It's OK if it writes an empty vector to Excel, I can quickly set up lower limit to disregard it. ***EDIT*** Yes, yes it will! That's wonderful, thank you for your help! Edited January 7, 2012 by Will0674
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now