Description
Use the Rect.Right
property to get or set the horizontal (X) coordinate of the rectangle’s right edge (relative to the screen).
Declaration
RectObj.Right
Read-Write Property | Integer |
RectObj | An expression, variable or parameter that specifies a reference to a Rect object |
Applies To
The property is applied to the following object:
Property Value
The horizontal coordinate of the rectangle’s right edge, in screen coordinates.
Example
The code below demonstrates how you can search for the desired image on a web page. To search the window, we use the Picture.Find
method. This method returns a rectangle that specifies the coordinates of the image within the web browser window. To calculate the coordinates of the image center, we use methods of the Rect
object. To obtain the scripting object corresponding to the found image, we use the Sys.Desktop.ObjectFromPoint
method. This method returns an onscreen
object that contains Click
and other actions, which you can use to simulate mouse clicks over the image.
JavaScript
function Test()
{
let url = "http://smartbear.com/";
// Launches the web browser and opens the web page
Browsers.Item(btIexplorer).Run(url);
let page = Sys.Browser().Page("*");
// Obtains the image of the browser window
let picture = page.PagePicture();
// Loads the sought-for image
let pict = Utils.Picture;
pict.LoadFromFile("c:\my_image.bmp");
// Searches for the image within the browser window
let rect = picture.Find(pict);
if (strictEqual(rect, null))
{
Log.Warning("The image was not found on the page.");
return;
}
// Calculates the coordinates of the image center
let x = page.ScreenLeft + rect.Left + rect.Width / 2;
let y = page.ScreenTop + rect.Top + rect.Height / 2;
// Obtains the IMG object by coordinates
let img = Sys.Desktop.ObjectFromPoint(x, y);
// Checks the results and simulates a mouse click over the image
if (img.Exists)
img.Click();
else
Log.Warning("Unable to simulate the click.");
}
JScript
function Test()
{
var url = "http://smartbear.com/";
// Launches the web browser and opens the web page
Browsers.Item(btIexplorer).Run(url);
var page = Sys.Browser().Page("*");
// Obtains the image of the browser window
var picture = page.PagePicture();
// Loads the sought-for image
var pict = Utils.Picture;
pict.LoadFromFile("c:\my_image.bmp");
// Searches for the image within the browser window
var rect = picture.Find(pict);
if (rect == null)
{
Log.Warning("The image was not found on the page.");
return;
}
// Calculates the coordinates of the image center
var x = page.ScreenLeft + rect.Left + rect.Width / 2;
var y = page.ScreenTop + rect.Top + rect.Height / 2;
// Obtains the IMG object by coordinates
var img = Sys.Desktop.ObjectFromPoint(x, y);
// Checks the results and simulates a mouse click over the image
if (img.Exists)
img.Click();
else
Log.Warning("Unable to simulate the click.");
}
Python
def Test():
url = "http://smartbear.com/"
# Launches the web browser and opens the web page
Browsers.Item(btIexplorer).Run(url)
page = Sys.Browser().Page("*")
# Obtains the image of the browser window
picture = page.PagePicture()
# Loads the sought-for image
pict = Utils.Picture;
pict.LoadFromFile("c:\my_image.bmp")
# Searches for the image within the browser window
rect = picture.Find(pict)
if rect == None:
Log.Warning("The image was not found on the page.")
return
# Calculates the coordinates of the image center
x = page.ScreenLeft + rect.Left + rect.Width / 2
y = page.ScreenTop + rect.Top + rect.Height / 2
# Obtains the IMG object by coordinates
img = Sys.Desktop.ObjectFromPoint(x, y)
# Checks the results and simulates a mouse click over the image
if img.Exists:
img.Click()
else:
Log.Warning("Unable to simulate the click.")
VBScript
Sub Test
Dim url, page, picture, pict, rect, img, x, y
url = "http://smartbear.com/"
' Launches the web browser and opens the web page
Browsers.Item(btIexplorer).Run(url)
Set page = Sys.Browser.Page("*")
' Obtains the image of the browser window
Set picture = page.PagePicture
' Loads the sought-for image
Set pict = Utils.Picture
pict.LoadFromFile("c:\my_image.bmp")
' Searches for the image within the browser window
Set rect = picture.Find(pict)
If rect Is Nothing Then
Call Log.Warning("The image was not found on the page.")
Exit Sub
End If
' Calculates the coordinates of the image center
x = page.ScreenLeft + rect.Left + rect.Width / 2
y = page.ScreenTop + rect.Top + rect.Height / 2
' Obtains the IMG object by coordinates
Set img = Sys.Desktop.ObjectFromPoint(x, y)
' Checks the results and simulates a mouse click over the image
If img.Exists Then
img.Click
Else
Call Log.Warning("Unable to simulate the click.")
End If
End Sub
DelphiScript
procedure Test;
var
url, page, picture, pict, rect, img, x, y : OleVariant;
begin
url := 'http://smartbear.com/';
// Launches the web browser and opens the web page
Browsers.Item(btIexplorer).Run(url);
page := Sys.Browser.Page('*');
// Obtains the image of the browser window
picture := page.PagePicture;
// Loads the sought-for image
pict := Utils.Picture;
pict.LoadFromFile('c:\my_image.bmp');
// Searches for the image within the browser window
rect := picture.Find(pict);
if rect = nil then
begin
Log.Warning('The image was not found on the page.');
Exit;
end;
// Calculates the coordinates of the image center
x := page.ScreenLeft + Rect.Left + Rect.Width / 2;
y := page.ScreenTop + Rect.Top + Rect.Height / 2;
// Obtains the IMG object by coordinates
img := Sys.Desktop.ObjectFromPoint(x, y);
// Checks the results and simulates a mouse click over the image
if (img.Exists) then
img.Click
else
Log.Warning('Unable to simulate the click.');
end;
C++Script, C#Script
function Test()
{
var url = "http://smartbear.com/";
// Launches the web browser and opens the web page
Browsers["Item"](btIexplorer)["Run"](url);
var page = Sys["Browser"]()["Page"]("*");
// Obtains the image of the browser window
var picture = page["PagePicture"]();
// Loads the sought-for image
var pict = Utils["Picture"];
pict["LoadFromFile"]("c:\my_image.bmp");
// Searches for the image within the browser window
var rect = picture["Find"](pict);
if (rect == null)
{
Log["Warning"]("The image was not found on the page.");
return;
}
// Calculates the coordinates of the image center
var x = page["ScreenLeft"] + rect["Left"] + rect["Width"] / 2;
var y = page["ScreenTop"] + rect["Top"] + rect["Height"] / 2;
// Obtains the IMG object by coordinates
var img = Sys["Desktop"]["ObjectFromPoint"](x, y);
// Checks the results and simulates a mouse click over the image
if (img["Exists"])
img["Click"]();
else
Log["Warning"]("Unable to simulate the click.");
}