Jump to content

Using the find function as a condition


Recommended Posts

Hello All.

I have a tricky situation.

I have written a script that will navigate through several webpages and enter in an account number. There are several possiblities on the outcome, but there is not a simple way to check what the outcome is.

So I am trying to create an if statement after having autoit view the source of the page.

I have autoit opening up the source in notepad, and then sending a ctrl + f to open up the find box.

I know what the different outcomes could be, and there is a distinct error message for each case.

What I would like to do is this.

If Search brings up "VW2398" then post error message to a flat file.

If Search brings up "VW4383" then post error message to a flat file.

If Search brings up "VW3828" then post error message to a flat file.

Else

Post valid transaction and $account number.

I hope I explained that well enough, and please help.

Thanks.

Link to comment
Share on other sites

Maybe this can help you. Its a modified version of a 'pop-up' script I half created.

It was designed to get the source code from my hotmail webpage and search through the source for a line of text. Depending on how many times it found it, that was how many new emails I had. I never finished it though but maybe it can help you.

InetGet("Enter the website to get the source of here", "test.txt")

$source = FileRead("test.txt",FileGetSize("test.txt"))

$Count = 0
$Count1 = 0
$Count2 = 0

While 1
   If stringInStr($source,"VW2398",0,$count+1) Then
      $count = $count + 1
   Else
      ExitLoop
   EndIf   
   If stringInStr($source,"VW4383",0,$count1+1) Then
      $count1 = $count1 + 1
   Else
      ExitLoop
   EndIf
   If stringInStr($source,"VW3828",0,$count2+1) Then
      $count2 = $count2 + 1
   Else
      ExitLoop
   EndIf
WEnd

$Errors = $count + $count1 + $count2

I cut most of it out and left the file searching part. I replaced what I was searching for, to what you want to.

The $Count variables were used to tell me how many new emails I had, so each time it finds the desired text in the file, it adds one to it. You can then remove those lines and replace it with your error message. It saves the source of the webpage to "test.txt" and will be located in the DIR where your running the script. $Errors is just the total number of times that it found "VW3828", "VW4383" and "VW2398".

Hope it helps.

Edited by Burrup

qq

Link to comment
Share on other sites

Thank you Burrup.

I really appreciate you posting that piece of code.

I am having some trouble with my variables.

I have a message box opening with the value that I am searching for before and after the stringInString statement.

The first message box displays WV2004, but the second message box that comes up shows 0.

Here is my code....Any ideas?

$Count = 0

$value1 = "WV2004"

MsgBox(0, "Value", $value1)

While 1

If stringInStr($source,$value1,0,$Count+1) Then

$Count = $Count + 1

MsgBox(0, "Value", $value1)

Else

ExitLoop

EndIf

-----> the code goes on....I just want to cut out the important section...

Thanks.

Link to comment
Share on other sites

It seems to be working fine for me. The 2nd msg box should be the same as the first, you havent altered $value1 in anyway. Post your code please so I can have a better understanding.

Edited by Burrup

qq

Link to comment
Share on other sites

I figured out what the problem is, but I do not have a solution. I am trying to access a secure (https) website that requires a password.

Although I have entered the password through the navigation process to that specific page, when I use the command InetGet(https://blah.com) it is directed to a login page, which does not have the error code WV2004.

So, is there anyway to grab the source from the page that I had navigated to?

I hope that I made it clear, it is a little difficult to explain.

Thanks.

$source = FileRead("test.txt",FileGetSize("test.txt"))

$Count = 0

$Count1 = 0

$Count2 = 0

$value1 = "WV2004"

MsgBox(0, "Value", $value1)

$result = StringInStr($source, $value1)

MsgBox(0, "Search result:", $value1)

While 1

If stringInStr($source,$value1,0,$Count+1) Then

$Count = $Count + 1

MsgBox(0, "Value", $value1)

MsgBox(0, "Value", $Count)

Else

ExitLoop

EndIf

If stringInStr($source,"VW4383",0,$Count1+1) Then

$Count1 = $Count1 + 1

Else

ExitLoop

EndIf

If stringInStr($source,"VW3828",0,$Count2+1) Then

$Count2 = $Count2 + 1

Else

ExitLoop

EndIf

WEnd

$Errors = $Count + $Count1 + $Count2

sleep(1000)

MsgBox(0, "Value", $Errors)

Link to comment
Share on other sites

I think this might work:

MouseClick("Left", 88, 36) ;opens the source

Sleep(200)

MouseClick("Left", 130, 221)

WinWaitActive("process[1] - Notepad","")

WinActive("process[1] - Notepad","")

Send("^f")

Send("WV3001")

Send("{ENTER}")

if WinExists("Notepad") Then

MsgBox(0, "Search result:", "No")

Else

MsgBox(0, "Search result:", "Yes")

EndIf

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...