Determine row in which a string is in an HTML table
Forum rules
iMacros EOL - Attention!
The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.
Thank you again for your business and support.
Sincerely,
The Progress Team
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
iMacros EOL - Attention!
The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.
Thank you again for your business and support.
Sincerely,
The Progress Team
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Determine row in which a string is in an HTML table
How can I determine in which row of a table a certain string is and save it into a variable using iMacros? (and use that position to later click a link with iMacros)
Thanks!
Thanks!
Re: Determine row in which a string is in an HTML table
CIM...! (Read my Sig...)golyalpha wrote:How can I determine in which row of a table a certain string is and save it into a variable using iMacros? (and use that position to later click a link with iMacros)
Thanks!
Interesting Case, ah-ah...!
But, yep..., I have a "Method" to do that, based a bit on my "Method to determine Dynamic ID's" but it's a bit "cumbersome" and you probably won't understand it if I have to explain it "generically"...
=> Post your URL with some concrete Example of what you want exactly... (Or some public Site with a concrete Example if you don't want to post your "real" URL... But try to find a very similar Table with the same HTML Structure as iMacros heavily relies on the HTML Structure of Pages/Elements...)
Oh...!, 2 Methods actually...! I already implemented this very same Functionality about 4 or 5 years ago and it still works fine, in some Script that I still use daily, even if I realize now that I would come up now with a much simpler Implementation, ah-ah...! But as it still works perfectly, I never bothered to redo/improve this part of Code...
Oh yeah...!, just checked it, and that was the longest 'EVAL()' Statement I ever produced, ah-ah...!, 1.6Kb (= 1600 Chars in just one Statement...!), oops...! Yep, I could definitely make it muuuuuch shorter now, but I didn't really master JavaScript Array Functions at that time...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Re: Determine row in which a string is in an HTML table
OS: Win10 x64 PRO
Browser: Firefox 54.0.1 x86
iMacros: Latest from Firefox Addons... (Not sure what version is there.)
Here's the link to a copied table from the page (the actual table is protected by login): http://imacros-table.9e.cz/
(there's some CSS on the actual page of course, and I added the "C" into link that the macro is supposed to click, just so you can see it, in the actual table, the "C" isn't there, there are some images placed by the CSS, and four (or five) different links in total)
Edit: You'll get a 404 error if you try to click that C. What's on the following page is not important though.
Browser: Firefox 54.0.1 x86
iMacros: Latest from Firefox Addons... (Not sure what version is there.)
Here's the link to a copied table from the page (the actual table is protected by login): http://imacros-table.9e.cz/
(there's some CSS on the actual page of course, and I added the "C" into link that the macro is supposed to click, just so you can see it, in the actual table, the "C" isn't there, there are some images placed by the CSS, and four (or five) different links in total)
Edit: You'll get a 404 error if you try to click that C. What's on the following page is not important though.
Re: Determine row in which a string is in an HTML table
FCI: Will probably be iMacros for FF v9.0.3 then...golyalpha wrote:Here's the link to a copied table from the page (the actual table is protected by login): http://imacros-table.9e.cz/Code: Select all
OS: Win10 x64 PRO Browser: Firefox 54.0.1 x86 iMacros: Latest from Firefox Addons... (Not sure what version is there.)
(there's some CSS on the actual page of course, and I added the "C" into link that the macro is supposed to click, just so you can see it, in the actual table, the "C" isn't there, there are some images placed by the CSS, and four (or five) different links in total)
Edit: You'll get a 404 error if you try to click that C. What's on the following page is not important though.
Check the Forum Rules btw if you want some Explanation on how to check your Version, ah-ah...!
Yep, no Pb for the Link...
Perfect-perfect for the Test Site with the more-or-less real Table I guess... That's perfect, exactly what I need to understand a bit and do some Testing...!
But hum, from the "concrete Example" I was asking, I miss the Info how do you know that "Target" is your "Target"...?
What is your "Input" info to take Decisions...?
(And hum..., I have the Feeling your Qt is about a Game, but I normally don't help Users (to cheat) for Games/Votes/Spam/Hacking/DDOS/SM/etc... But, OK, fire it, and I'll see...!)
Consider checking "Relative Positioning", until I have all Info about what exactly you want to do, I have a "Feeling" that "RP" could be your easiest Solution, ah-ah...!
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Re: Determine row in which a string is in an HTML table
That string "Target" will be replaced by something else. The problem is, that while the string will always be in that table, it can move around a lot (sometimes it can be on the second row, sometimes on the 10th...). User could either input the correct string to search for in the table through an input box that would pop up at the begining of a macro.
Re: Determine row in which a string is in an HTML table
Well, simply use Relative Positioning like I suggested:golyalpha wrote:That string "Target" will be replaced by something else. The problem is, that while the string will always be in that table, it can move around a lot (sometimes it can be on the second row, sometimes on the 10th...). User could either input the correct string to search for in the table through an input box that would pop up at the begining of a macro.
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
TAB T=1
URL GOTO=http://imacros-table.9e.cz/
TAG POS=1 TYPE=TD ATTR=TXT:Target
TAG POS=R1 TYPE=SPAN ATTR=TXT:C
Or this one works as well for your Table:
Code: Select all
VERSION BUILD=8820413 RECORDER=FX
TAB T=1
URL GOTO=http://imacros-table.9e.cz/
TAG POS=1 TYPE=TD ATTR=TXT:Target
'TAG POS=R1 TYPE=SPAN ATTR=TXT:C EXTRACT=HTM
'TAG POS=R2 TYPE=A ATTR=TXT:* EXTRACT=HTM
TAG POS=R2 TYPE=A ATTR=TXT:*
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
-
- Posts: 4
- Joined: Fri Aug 18, 2017 6:25 pm
Re: Determine row in which a string is in an HTML table
I am having a similar issue. I've found a solution in JQuery that searches for a TD with a specified word and returns its row number but adding it to a macro (or JS in iMacros) has been too difficult for me to figure out. I'm interested to see where this goes and I'll post the JQuery below in case it helps someone.
Hope we get a solution for this!
Code: Select all
$("tr td:contains('WORDTOSEARCHFOR')").each(function(){
var $tr = $(this).closest('tr');
var myRow = $tr.index();
alert(myRow) ;
});
Re: Determine row in which a string is in an HTML table
(F)CIM...! (Read my Sig...)cbelerique wrote:I am having a similar issue. I've found a solution in JQuery that searches for a TD with a specified word and returns its row number but adding it to a macro (or JS in iMacros) has been too difficult for me to figure out. I'm interested to see where this goes and I'll post the JQuery below in case it helps someone.
Hope we get a solution for this!Code: Select all
$("tr td:contains('WORDTOSEARCHFOR')").each(function(){ var $tr = $(this).closest('tr'); var myRow = $tr.index(); alert(myRow) ; });
I have a fairly simple Solution in pure '.iim' which is actually very similar to yours in JQuery, with a Double 'split()' (on your Search Keyword and on "tr" as well...!) + the 'length' Property of the Array returned by 'split()' (-1) which is similar to your 'index()'...
But what is your Purpose for the Row-Nb...? Like @OP, if you need it to reuse it for some further Action (Select/Tag/Input/Extract) in the same Table on the same Row, then is Relative Positioning even much simpler to use, like I demonstrated for @OP... (who didn't follow up anymore btw, grrr...!).
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...