Perllace has asked for the wisdom of the Perl Monks concerning the following question:
sub FindInHorizontalRegion { print "Inside FindInHorizontalRegion"; my ( $self,$element1,$element2,$duration,$threshold) = @_; my ($xcoord1,$ycoord1, $xcoord2, $ycoord2); my $regex1 = '(.*?)\:(.*?)'; print "Damn the element1 is $element1 \n"; if ( $element1 =~ m/$regex1/g ) { print "Inside wait for image \n"; my $region = $self->WaitForImage( $element1, $duration ); $xcoord1 = $region->getX; $ycoord1 = $region->getY; print "The coordinates of element1 are $xcoord1, $ycoord1 +\n"; } else { print "Inside wait for Text \n"; my $region = $self->WaitForText( $element1, $duration ); $xcoord1 = $region->getX; $ycoord1 = $region->getY; print "The coordinates of element1 are $xcoord1, $ycoord1 \n"; + } if ( $element2 =~ m/$regex1/g ) { my $region = $self->WaitForImage( $element2, $duration ); $xcoord2 = $region->getX; $ycoord2 = $region->getY; print "The coordinates of element2 are $xcoord1, $ycoord1 \n"; } else { my $region = $self->WaitForText( $element2, $duration ); $xcoord2 = $region->getX; $ycoord2 = $region->getY; print "The coordinates of element2 are $xcoord1, $ycoord1 \n"; } my ($x1,$y1,$x2,$y2) = $self->GetHorizontalCoord($xcoord1,$ycoord1 +,$xcoord2,$ycoord2,$threshold); print "The horizontal coordinates are $x1,$y1,$x2,$y2 \n"; print "The element1 is $element1 \n"; if ( $element1 =~ m/$regex1/g ) { print "To check for iImage"; my $region = $self->WaitForImageInROI($element1,$x1,$y1,$x2,$y +2,$duration); return ($region); } else { print "To check for tText"; my $region = $self->WaitForTextInROI($element1,$x1,$y1,$x2,$y2 +,$duration); return ($region); } } sub GetHorizontalCoord { print "Inside GetHorizontalCoord"; my ( $self,$xcoord1,$ycoord1,$xcoord2,$ycoord2,$threshold ) = @_; my $width = $self->GetDeviceProperty('Width'); my $height = $self->GetDeviceProperty('Height'); my $x1 = 0; my $x2 = $width; my $y1 = $ycoord1 - $threshold ; if ($y1<0) { $y1 = 0; } my $y2 = $ycoord2 + $threshold; if ($y2 > $height) { $y2 = $height; } return ($x1,$x2,$y1,$y2); }
The input in the script goes something like this
my $region = $object->FindInHorizontalRegion('SETTINGS:Flight','SETTIN +GS:Tick','1000',10);
I need to pass SETTINGS:Flight to WaitForImageInROI, instead, the if condition is failing and it is invoking WaitForTextInROI. The problem is that in these lines,
my ($x1,$y1,$x2,$y2) = $self->GetHorizontalCoord($xcoord1,$ycoord1,$xc +oord2,$ycoord2,$threshold); print "The horizontal coordinates are $x1,$y1,$x2,$y2 \n"; print "The element1 is $element1 \n"; if ( $element1 =~ m/$regex1/g ) { print "To check for iImage"; my $region = $self->WaitForImageInROI($element1,$x1,$y1,$x2,$y +2,$duration); return ($region); } else { print "To check for tText"; my $region = $self->WaitForTextInROI($element1,$x1,$y1,$x2,$y2 +,$duration); return ($region); }
though element1 is SETTINGS:Flight, the else condition is getting executed. While the same regex works for the previous if conditions, I'm not able to understand why it does not work here.
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex not working
by jethro (Monsignor) on Sep 12, 2011 at 13:27 UTC | |
|
Re: Regex not working
by toolic (Bishop) on Sep 12, 2011 at 13:16 UTC | |
by Perllace (Acolyte) on Sep 13, 2011 at 04:27 UTC | |
by graff (Chancellor) on Sep 13, 2011 at 08:35 UTC | |
by Perllace (Acolyte) on Sep 14, 2011 at 05:45 UTC | |
|
Re: Regex not working
by RichardK (Parson) on Sep 12, 2011 at 13:46 UTC | |
by toolic (Bishop) on Sep 12, 2011 at 14:04 UTC |