How to use If-else on webpage

Hi, friends.
How do I add these to “if-then-else” when the search isn’t found? Thanks

@KunSeng

use Get Text activity and indicate no results found position. And it will give you output of type String and say ‘searchResult’

If searchResult.Contains(“No result found”)
Then data not found
Else Found it.

1 Like

Ok, so do I need to add any variable?

@KunSeng

Yes create one variable of type string and store output of Get Text activity into it.

So, what you mean is the variable is NoSearchResult, right?

@KunSeng

You can declare variable name anything but it should be of type ‘String’.

Ok, so the GetText of no result found should before the *If-then-else?

1 Like

The system dectected error once I added “Get Text” into the process

@KunSeng

  1. Type Salesperson’s Mobile Number

  2. Click Search

  3. use Get Text activity and indicate that position to read status like whether data found or not. And store result in a string variable say ‘searchResult’

                  If searchResult.Contains("No result found")
                  Then:
                             Results not found
                  Else:
                             Results found
    

Yes you’re right.

Important thing is when you use ‘Get Text’ activity, don’t use the value attribute in selector if the value was dynamically change.

TanQ,
Michael Udhaya

I did use the Get text to indicate the no result found but the error will still appear after the Search is clicked
PS: The Get textthat to indicate the No result found must be inside the If-then-else ?

Guys, please help. I tried a lot of times to solve the errors T T.

And these are the variables that I created

get text activity must be before if condition…

also I would like to advise to you take basic training so that you can have better understanding of what to do, when to do, how to do…

https://academy.uipath.com/learn/public/learning_plan/view/35/RPADeveloper

So, Do I need to input 2 Get Text into the process when I have 2 conditions?

if your condition is checking for two different things then yes…

Thanks, Friends! I think one of the condition is work when my “No result found”. However, when condition 2 is meet which is the result is found but the system showed the error again.


How should I do to let the system to run when the condition 2 is meet?

This is what the webpage would show when the result is found

@KunSeng let me explain.

  1. You enter some values in text box and Click the Search button.
  2. Use the ‘Element Exists’ activity to check the “No Results Found”.(use aaname attribute for better selector)
  3. Get the Boolean variable of ‘Element Exists’ and paste it in the ‘If condition’.
  4. In the ‘Then’ block simply put a ‘Log Message’ for your reference.
  5. In the Else block you can do the data scraping or what do you want.

Surly it will work. Let me know once you got.

TanQ,
Michael Udhaya