Click button with changing content (select by class?)

Discussions and Tech Support related to the iMacros Google Chrome extension.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Click button with changing content (select by class?)

by nicholmikey on Wed May 10, 2017 12:56 pm

I have a loop setup that loads every language that my website has (12 languages).

I want the loop to click on the login button, but the CONTENT changes based on the language. For example "continue" becomes "Continua" in Italian. The macro recorder uses the "continue" text for it's selector which is breaking the loop when the text changes.

How can I click a button based on CSS class instead? I see examples of extracting content with a class but no example of clicking a button.

Thank you,
nicholmikey
 
Posts: 2
Joined: Wed May 10, 2017 12:51 pm

Re: Click button with changing content (select by class?)

by chivracq on Wed May 10, 2017 1:58 pm

nicholmikey wrote:I have a loop setup that loads every language that my website has (12 languages).

I want the loop to click on the login button, but the CONTENT changes based on the language. For example "continue" becomes "Continua" in Italian. The macro recorder uses the "continue" text for it's selector which is breaking the loop when the text changes.

How can I click a button based on CSS class instead? I see examples of extracting content with a class but no example of clicking a button.

Thank you,

Low Quality Thread...! :mrgreen:

=> (F)CIM...! :mrgreen:

- Thread opened in the 'iMacros for CR' Sub-Forum, but nothing specific to only CR..., especially if FCI not even mentioned, correct Sub-Forum would have been 'General' Sub-Forum... (No need to spam-duplicate...)
- FCI missing, read my Sig (and the Forum Rules) for Required Info to include when you open a Thread...
- No URL...
- No Script...

=> Generic Answer, pfff..., difficult to help you because of the Low Quality of your Thread, try using Wildcards and/or Attributes that remain Constant over the whole Site in the different Languages... Relative Positioning could maybe help as well, but, pfff, difficult to be more precise...!

Good luck or give more Info, and mention your FCI as a Condition anyway for me to follow up... (and to help you (again) in the future...) :idea:

How can I click a button based on CSS class instead? I see examples of extracting content with a class but no example of clicking a button.

Well, a 'Button' is just an HTML Element like all others, and the 'CLASS' of that Element is just an Attribute like all others, so if you already have an Example of tagging any HTML Element by using its Class, you can very easily and straightforwardly apply it to your 'Button'... :idea:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6307
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Click button with changing content (select by class?)

by nicholmikey on Wed May 10, 2017 2:20 pm

Ok well, sorry for the low quality..

Anyway I solved this issue myself.

you CAN use a CSS class to select a button like so:

TAG POS=1 TYPE=BUTTON ATTR=CLASS:myCssClass

And you don't need to specify CONTENT. I think it would be handy to newbies to add this CSS example to the wiki page here http://wiki.imacros.net/TAG

One issue I ran into was my button has 2 css classes. If you enter just 1 class it will not work, you need to enter all CSS classes with a '*' replacing any spaces. If you leave spaces in your CSS classes you will get a syntax error.

Example: TAG POS=1 TYPE=BUTTON ATTR=CLASS:myCssClass1*myCssClass2

Hopefully this helps someone in the future.
nicholmikey
 
Posts: 2
Joined: Wed May 10, 2017 12:51 pm

Re: Click button with changing content (select by class?)

by chivracq on Wed May 10, 2017 2:46 pm

nicholmikey wrote:Ok well, sorry for the low quality..

Anyway I solved this issue myself.

you CAN use a CSS class to select a button like so:
Code: Select all
TAG POS=1 TYPE=BUTTON ATTR=CLASS:myCssClass 


And you don't need to specify CONTENT. I think it would be handy to newbies to add this CSS example to the wiki page here http://wiki.imacros.net/TAG

One issue I ran into was my button has 2 css classes. If you enter just 1 class it will not work, you need to enter all CSS classes with a '*' replacing any spaces. If you leave spaces in your CSS classes you will get a syntax error.

Example:
Code: Select all
TAG POS=1 TYPE=BUTTON ATTR=CLASS:myCssClass1*myCssClass2


Hopefully this helps someone in the future.

OK, quick Follow-up (very good...!) and sharing your Solution is another of my "Criteria" for helping Users (again) in future Threads, but you should still mention your FCI in this one like I asked you, I won't react otherwise, next time you open a Thread... :idea:

Hum, I don't think your Button has 2 Classes, its Class simply contains a Space in it, which is a very common Practice among Web-Devs to reuse some "Up-Level" (usually at some 'DIV' Level) Class with sometimes several Levels of "Sub-Classes" in the Class-Name (it's a bit like a Naming Convention), and yep, using a Wildcard is one Solution, or replacing those Spaces with '<SP>' is another one, like iMacros itself automatically records when using the 'Full HTML' Record Mode.

No need to update the Wiki I'm afraid, ah-ah...!, a 'TYPE=BUTTON' HTML Element doesn't have any 'CONTENT' Parameter anyway I would think... Tagging it means clicking on it, same with 'Links' ('TYPE=A'). The 'CONTENT' Parameter is for 'INPUT', 'SELECT', 'CHECKBOX', 'RADIO', etc... Elements...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6307
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to iMacros for Chrome

Who is online

Users browsing this forum: No registered users and 3 guests

-->