Imacros - Extract and select multiple items from selector via predefined variable - extract

I'm trying to EXTRACT some content from a table to be used for selecting items on a select multiple box.
This works fine:
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple
FRAME NAME="iframeResult"
TAG POS=1 TYPE=SELECT FORM=ACTION:/action_page.php ATTR=NAME:cars CONTENT=%volvo:%opel
How come that when creating the extract content as a variable, then it does not work:
The variable called SET CARS volvo:%opel
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple
FRAME NAME="iframeResult"
SET CARS volvo:%opel
TAG POS=1 TYPE=SELECT FORM=ACTION:/action_page.php ATTR=NAME:cars CONTENT=%{{CARS}}
Error message:
Entry [volvo:%opel] not available [Box has 4 entries], line: 6 (Error code: -924)

In addition I can suggest another way:
' ... '
FRAME NAME="iframeResult"
SET CARS "volvo,opel"
EVENT TYPE=CLICK XPATH=EVAL("'//HTML/BODY/FORM/SELECT/OPTION[#value=\\'' + '{{CARS}}'.split(',')[0] + '\\']';") BUTTON=0 MODIFIERS="ctrl"
EVENT TYPE=CLICK XPATH=EVAL("'//HTML/BODY/FORM/SELECT/OPTION[#value=\\'' + '{{CARS}}'.split(',')[1] + '\\']';") BUTTON=0 MODIFIERS="ctrl"
According to the wiki documentation you have to write the code like this:
' ... '
FRAME NAME="iframeResult"
SET CAR1 "volvo"
SET CAR2 "opel"
TAG POS=1 TYPE=SELECT FORM=ACTION:/action_page.php ATTR=NAME:cars CONTENT=%{{CAR1}}:%{{CAR2}}

Found a way using the script interface. Simply add the list of items to select usign JS:
function createMultiSelector(list) {
macro = "CODE:";
macro += "URL GOTO=https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_select_multiple\n";
macro += "FRAME = 'iframeResult'\n";
macro += "TAG POS=1 TYPE=SELECT FORM=ACTION:/action_page.php ATTR=NAME:cars CONTENT=%"+list+"\n";
iret = iimPlay(macro);
}

Related

iMacros - extracting text

Can you explain to me why my EXTRACT doesn't work? I am trying to count the number of users with private profiles in my group (because mostly these are bots). So I need to check whether the string "This profile is private" exists on the user's page.
After the code runs, a blue frame appears around the DIV which means the element is pinned correctly. However, the extract result is NaN.
I tried extracting both TXT and HTM.
iimPlay("CODE:TAG POS=1 TYPE=DIV ATTR=TXT:This<SP>profile<SP>is<SP>private EXTRACT=TXT");
var pageblock = parseInt (iimGetLastExtract());
alert (pageblock);
An example page with a private profile:
https://vk.com/id646170325
I tried extracting both TXT and HTM.
Yep normal..., no way you can convert the extracted This profile is private (is a String) to an Integer...!, ... which is what parseInt() is trying to do..., => Result = NaN...
=> The Behaviour/Result looks then "normal" to me...

VBA Excel IE automation: locate element by custom tag

I need to pick out an element by a custom html tag - ie, where the custom tag would be "somecustomtag" in the following div element
<div class="panel-one" somecustomtag="blue">
I just can't remember the sytax. I know it's something like:
Set myElements = IE.Document.getElementsbyTagName("div")
For Each ob in myElements
If ob.subTag("somecustomtag") = "blue" then ' ????????
someStringVariable = ob.innerText
exit for
End If
Next ob
I've used this a dozen times before but can't find it any where. What is the proper syntax for .subTag?
In your case somecustomtag is an attribute. You will get the value of somecustomtag with the following code snippet
ob.getAttribute("somecustomtag")

iMacros read column .csv from choice of user between 1 to 10

I have a question that is similar to the following link:
iMacros: user defined variables within !COLn?
I've tried that apply to my script (bellow) but error, like this:
SyntaxError: unterminated string literal, line 12 (Error code: -1001)
line 12 is :
SET col EVAL("var col=eval('[{{row}}]'); col[{{!VAR1}} - 1];")
The following is my full script with the same question, NEED TO ENTRY TEXT FROM .CSV FILE, BUT iMacros READ COLUMN IS FROM CHOICE OF USER BETWEEN 1 to 10.
VERSION BUILD=8871104 RECORDER=FX
TAB T=1
SET !REPLAYSPEED FAST
SET !TIMEOUT_PAGE 10
SET !TIMEOUT_STEP 1
SET !DATASOURCE c:\option\abc.csv
SET !DATASOURCE_LINE 2
PROMPT "Please enter CSV column:\n\n1. Red \n2. Green \n3. Blue \n4.so on" !VAR1
SET row "'{{!COL1}}', '{{!COL2}}', '{{!COL3}}', '{{!COL4}}', '{{!COL5}}', '{{!COL6}}', '{{!COL7}}', '{{!COL8}}', '{{!COL9}}', '{{!COL10}}'"
SET col EVAL("var col=eval('[{{row}}]'); col[{{!VAR1}} - 1];")
EVENT TYPE=MOUSEUP POINT="(679,785)"
EVENTS TYPE=KEYPRESS SELECTOR="#main>FOOTER>DIV:nth-of-type(2)>DIV>DIV>DIV:nth-of-type(2)" CHARS={{col}}
SyntaxError: unterminated string literal is likely a browser issue while parsing the code within the eval, for me your code works 100% out of the box.
Try line 12 like this (by removing [ ]):
SET col EVAL("var col=eval('{{row}}'); col[{{!VAR1}} - 1];")
Else, run your code with a different browser/version.

How to EXTRACT and save Url in CSV using IMACROS

Trying to get contents and saving them in a CSV, one per row
But when it has a WEBLINK, the URL gets messed up.
See the latest
Actually the glassdoor.com/Top-Companies-... part is a hyperlink to following weblink
http://t.co/tDbVGX48c6
which redirects to
http://www.glassdoor.com/Top-Companies-for-Culture-and-Values-LST_KQ0,36.htm
**ISSUE is if we use the following to save this **
TAG POS=1 TYPE=DIV ATTR=CLASS:dir-ltr EXTRACT=TXT
SAVEAS TYPE=EXTRACT FOLDER=* FILE=Save.csv
it is saved in CSV as following only (i.e TEXT) & the link is not saved properly.
Honored to be named #Glassdoor's top company for culture and values. #jointheflock glassdoor.com/Top-Companies-...
**How can we make sure we get ACTUAL link saved in CSV, for every one
I feel EVAL & thus Javascript command can be used but i am not sure how.
I am using WINDOWS XP 64 Bit with Latest Firefox Imacros Addon
Thanks
Take a look at the EXTRACT definition on the iMacros wiki. You can use HREF as the extract type to extract the link instead of the text for that anchor. The following example extracts the link and saved it to a file.
VERSION BUILD=8820413 RECORDER=FX
TAB T=1
TAB CLOSEALLOTHERS
URL GOTO=http://www.penny-arcade.com/
TAG POS=1 TYPE=A ATTR=TXT:Forum EXTRACT=HREF
SAVEAS TYPE=EXTRACT FOLDER=* FILE=FORUMS.CSV
Here is the macro code for the twitter page:
TAG POS=1 TYPE=A ATTR=CLASS:twitter-timeline-link EXTRACT=HREF
SAVEAS TYPE=EXTRACT FOLDER=* FILE=SaveTweets.csv
Here is a javascript version that pulls each tweet and a link it if exists.
var retcode, tagText, tweetCounter, startIndex, endIndex, macro, extractMacro;
extractMacro = "";
macro = "CODE:";
macro += "URL GOTO=https://twitter.com/twitter\n";
retcode = iimPlay(macro);
tweetCounter = 1;
do
{
extractMacro = "CODE:";
macro = "CODE:";
macro += "TAG POS=" + tweetCounter + " TYPE=P ATTR=CLASS:ProfileTweet-text<SP>js-tweet-text<SP>u-dir EXTRACT=TXT\n";
retcode = iimPlay(macro);
tagText = iimGetLastExtract();
// iMacros code requires <SP> for spaces
tagText = tagText.replace(/[ \s\t\n]/g, "<SP>");
// Add extracted value to another macro for extraction later
extractMacro += "ADD !EXTRACT " + tagText + "\n";
macro = "CODE:";
macro += "TAG POS=" + tweetCounter + " TYPE=DIV ATTR=CLASS:ProfileTweet-Contents EXTRACT=HTM\n";
retcode = iimPlay(macro);
tagHTML = iimGetLastExtract();
tweetCounter++;
startIndex = 0;
do
{
startIndex = tagHTML.indexOf("data-expanded-url=", startIndex + 1);
endIndex = tagHTML.indexOf(" ", startIndex);
if (startIndex > 0)
{
var linkText = tagHTML.substring(startIndex + 'data-expanded-url="'.length, endIndex - 1);
// iMacros code requires <SP> for spaces
linkText = linkText.replace(/[ \s\t\n]/g, "<SP>");
extractMacro += "ADD !EXTRACT " + linkText + "\n";
}
} while (startIndex > 0);
// Save extracted data
extractMacro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=SaveTweets.csv\n";
retcode = iimPlay(extractMacro);
}
while (tagText !== "#EANF#");

tt_news - where is the register "newsMoreLink" be defined?

The extension tt_news is very useful for me but there is this little thingy called "register:newsMoreLink". This register does contain the singlePid of the contentelement (defined a single view page) and the uid of the newsarticle from the news extension.
This is the typoscript section of the "new ts" of the extension tt_news
As you can see there is "append.data = register:newsMoreLink"...
plugin.tt_news {
displayLatest {
subheader_stdWrap {
# the "more" link is directly appended to the subheader
append = TEXT
append.data = register:newsMoreLink
append.wrap = <span class="news-list-morelink">|</span>
# display the "more" link only if the field bodytext contains something
append.if.isTrue.field = bodytext
outerWrap = <p>|</p>
}
}
}
What is "register:newsMoreLink"? Is this like a function or something? I do not know. But "register:newsMoreLink" produces a strange link if I use this on "append.data". It produces are "More >" link. The "More >" link after a news article teaser looks like this:
http://192.168.1.29/website/index.php?id=474&tx_ttnews%5Btt_news%5D=24&cHash=95d80a09fb9cbade7e934cda5e14e00a
474 is the "singlePid" (this is what it calls in the database
24 is the "uid" of the news article (the ones you create with the tt_news plugin in the backend)
My question is: Where is the "register:newsMoreLink" defined? Is it defined generally or do I miss a fact of Typo3..? How can I add an anchor link at the end of this "More >" href? Like:
http://192.168.1.29/website/index.php?id=474&tx_ttnews%5Btt_news%5D=24&cHash=95d80a09fb9cbade7e934cda5e14e00a#myAnchor1
register:newsMoreLink is not a function. It's one of the data types. In other words a type of data that you can access with stdWrap.data. register is set with LOAD_REGISTER. Though, in case of tt_news this is set in the PHP code with $this->local_cObj->LOAD_REGISTER().
I'm afraid you cannot easily add an anchor to that link. However, you can set the append to create your own custom link to the news record using typolink:
append = TEXT
append {
value = text of the link
typolink {
# ...typolink configuration...
}
}
You shall be interested in the typolink's attributes parameter, additionalParams and section.
this is the code I use to link to an pid with a anchor target:
displayList.plugin.tt_news.subheader_stdWrap {
append = TEXT
append.data >
append {
value = mehr
typolink{
parameter = 47 // pid
section = entry_{field:uid} // anchor name
section.insertData = 1
}
}