0
votes

I'm trying to use autohotkey to gather a chuck of data from a website and then click a certain spot on the website depending on what the text is. I'm able to get it to actually pick up the value but when it comes to the if statement it won't seem to process and yields no error message. Here is a quick sample of my code, there is about 20 if statement values so for brevity sake I've only included a few of the values.

GuessesLeft = 20
Errorcount = 0
;triple click and copy text making a variable out of the clipboard
;while (GuessesLeft!=0) part of future while loop
;{ part of future while loop
click 927,349
click 927,349
click 927,349

Send ^c

GetValue = %Clipboard%

if ( GetValue = "Frontal boss")
{
    click 955,485
    Guessesleft -= 1 
}

else if ( GetValue = "Supraorbital Ridge")
{
    click 955,571
    Guessesleft -= 1 
}
;....ETC
else
{
    Errorcount += 1
}
;} part of future while loop

Any tips on what I might be doing wrong. Ideally I'd use a case statement but AHK doesn't seem to have them.

1
Your code works. If the string Frontal Boss is in the clipboard, the first if statement is taken. The problem must be elsewhere. - 2501
Any ideas where I might look? I've tested the variable and it does seem to be accurately pulling it. - Rumen
2501: I think the string Frontal Boss must also have quotes around it, "Frontal Boss" and be the entirety of the copied text in the Clipboard -- rather than some portion of that text. And, triple clicking a paragraph on a webpage will likely include some additional non-printing characters at the end which will need to be trimmed off. I address these possibilities in my answer, but ultimately the OP should have been more clear what he or she wants . . . - PGilm
@PGilm It works without quotes. OP's string probably had some whitespace around it so the comparison didn't yield true. - 2501

1 Answers

0
votes

Wait a second -- you are triple clicking to highlight a full paragraph and copying that to the clipboard and checking to see if the entirety of the copied portion is the words in the if statement, right? And your words in the copied portion have quotes around them? Probably you will have to trim off any trailing spaces and/or returns:

GetValue = % Trim(Clipboard)

If that doesn't work, you may even have to shorten the length of the copied text by an arbitrary character or two:

GetValue = % SubStr(Clipboard, 1, (StrLen(Clipboard)-2))

Now, if I am wrong, and what you are really looking for is the words from the if statement wherever they may be in a longer paragraph -- and they are not surrounded by quotes, then you will want something like:

IfInString, Clipboard, Frontal boss

Or, if the quotes ARE there,

IfInString, Clipboard, "Frontal boss"

Hth,