How do I use html innertext in an if statement?

I’ve managed to find an innertext which I would like to use an if statement for.
e.g If InnerText=Digit1 then [activity]
and I have 9 different innertexts that it could possibly be, so I would probably just copy the same if statement and adjust 8 more times unless there is a smarter way to design it. My issue is i’m not sure how to write a visual basic expression to link to the innertext field, is there any documentation on how to do this?

Not all parts from the question are clear. Maybe following helps
grafik
we can check if an array has a particular item

Or

we will store our variables within an array and will check with the Any method if any item will satisfy a check condition
grafik

1 Like

Use Get Attribute to get innertext and store it in a variable. Use a Switch to do the 9 different things based upon the variable value.

By the way, instead of using Get Attribute to get innertext, just use the Get Text activity.

Thanks, that makes sense. I actually have 3 pop ups in the web page at any given time and each one has a different inner text so I was going to use that, but I guess text should work just as well. I think switch would work better if it was just the one inner text, otherwise I’d have to have 3 long switches?

Thanks Peter as well, that helps a lot with understanding the expression I need to write

No, your situation is exactly what Switch is for. You provide the value (ie the variable) in the expression similar to an If. Then you have a Case for each possible value. You get the value with a Get Text and put it into a variable, then you use Switch to do the other steps you need based on the variable’s value.

Thanks, I’ve used get text to assign each of the possible innertext fields to a variable.
I now have 3 variables, but when I use the switch and set the switch type to string it says along the lines of compiler error; disallows conversion from boolean to string.

The expression i’ve tried to use is {firstdigit}.Contains(“Digit 1, Digit 2, Digit 3”) and I would have a click sequence if this is true, another click sequence for Digits 4 to 6 and another for 7 to 9.

That’s not right. You use Get Text to get the value of the UI Element into a variable. Put that variable in your Switch expression (make sure to change its type to String), and then each possible value will be a Case.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.