cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
donaldekpe
Helper II
Helper II

Javascript Conditional Logic - How can I click a button if a span has a particular sibling?

 

 

<a class="item">
<span class="item_label">BIG_1</span>
<span class="acitve-high">...</span>
</a>
<a class="item">
<span class="item_label">BIG_2</span>
<span class="acitve-low">...</span>
</a>


<a class="button-high">...</a>
<a class="button-low">...</a>

 

 

 

How can I achieve the following actions using jquery function?

If the span containing text "BIG_1" has a sibling with class name "active-high" then click button with class name "button-high"
else if span containing text "BIG_1" has a sibling with class name "active-low" then click button with class name "button-low"


In the HTML, the span with text BIG_1 currently has a sibling with class name "active-high". I want the code to always check if this is true and then click a button with class name "button-high" if so. The website is dynamic and so the span with class name "active-high" sometimes automatically changes to "active-low". So, I want the code to click the button with class name "active-low" instead every time this change occurs.

Please note: More than one span has the class name "item_label" so I can't use the class name to identify the span with text BIG_1. Also, I can't use its position either because that changes automatically from time to time as well.

5 REPLIES 5
Ankesh_49
Super User
Super User

@donaldekpe Could you please share the website URL?

Henrik_M
Super User
Super User

Add two UI elements:

a:contains(BIG_1) > span[class="active-high"]​
a:contains(BIG_1) > span[class="active-low"]​

 This will find the span element with classes "high/low-active" within an a containing the text "BIG_1"

 

Add UI elements:

a[class="button-high"]​
a[class="button-low"]​

 

Then add your If web page contains conditional actions. I think you can edit the second If into an Else if if you copy the actions into notepad, then add ELSE in front, before copying back into PAD.

That is exactly what I have in the flow already. I want to convert them to javascript because they are so many of them in the flow and the UI Element attached to each is seriously weighing and slowing down PAD. I just believe using javascript instead will speed things up, I may be wrong though.

Would have loved to but it is kind of a private website and you need to have a paid account to access it.

Henrik_M
Super User
Super User

Aahhhh... Didn't read the JavaScript part 🤐

 

This seems useful: https://stackoverflow.com/questions/31044/is-there-an-exists-function-for-jquery 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,140)