WebDriver Mouse and Keyboard Events
WebDriver testing with Eggplant Functional and SenseTalk lets you automate actions in browsers and web apps by accessing WebElement objects (HTML elements) in the DOM of the pages you're testing. Use the commands and functions described here to perform Mouse and Keyboard events in your SenseTalk scripts based on Selenium WebDriver connections.
WebElement Identifiers
To access a WebElement within the DOM, such as when using the FindElement() function or the Click command with a WebDriver connection, you have several ways to specify the element you want to interact with. The following WebElement Identifiers can be used to locate elements in the DOM:
- webID: Use this property to locate an element by the value of its ID attribute.
- webName: Use this property to locate an element by the value of its Name attribute.
- webTagName: Use this property to locate an element whose HTML tag is equal to the given value.
- webClassName: Use this property to locate an element by the value of its Class attribute.
- webLinkText: Use this property to locate a link whose text is equal to the indicated value.
- webPartialLinkText: Use this property to locate a link whose text contains the indicated value.
- webCssSelector: Use this property to locate an element using the indicated CSS selector expression.
- webXPath: Use this property to locate an element by using an XPath expression. For information about XPath and XPath expressions, see XPath in Selenium WebDriver: Complete Tutorial.
WebLocation Identifier
A WebLocation Identifier is another method you can use to interact with WebElements. A WebLocation Identifier is a property list that contains objectType, x, and y properties. The objectType is always webLocation, and the x and y properties represent the coordinates of a point on the web page. For example:
{objectType:"webLocation", x:"476", y:"83"}
Typically, you would use coordinates for where a WebElement is located. The FoundWebLocation() function returns the WebLocation property list for found WebElements.
Mouse Events
You can use the following SenseTalk commands to simulate mouse events on WebElements with WebDriver connections.
Click Command
This code definition explains the use of the Click command for WebDriver connections. For information about using this command for image-based scripting, see Mouse Events and Control: Click Command.
Behavior: The Click command locates an element within the DOM and simulates a click event at the found location.
Parameters: A property list containing a required WebElement Identifier and an optional WaitFor property. Alternatively, you can provide a property list that contains a WebLocation Identifier, in which case a WaitFor property is irrelevant.
You can also pass multiple WebElement Identifiers, in which case, each should be included as a separate property list. When you pass more than one WebElement, Eggplant Functional searches for them in the order you list them in the command. If you include WaitFor properties in multiple property lists, SenseTalk uses only the longest WaitFor value for the entire command. That is, it doesn't apply that property multiple times.
Syntax:
Click { identifierType: value {, waitFor: duration} }
Click { objectType: "webLocation", x: valueX , y: valueY }
Click { identifierType: value {, waitFor: duration} } {, { identifierType2: value2 {, waitFor: duration2} }, ... }
Example:
click (webName:"q")
Example:
Click {webid:"uh-signin",waitFor:10}
Example:
if webElementFound(WebID:"login-username",WaitFor:10)
Click the FoundWebLocation // Clicks at the web location of the login-username web element
end if
Example:
set CheckBoxes to FindElements(WebCSSSelector:"input[type=checkbox]:not([checked])")
repeat with each CheckBox of CheckBoxes
Click CheckBox
end repeat
DoubleClick Command
This code definition explains the use of the DoubleClick command for WebDriver connections. For information about using this command for image-based scripting, see Mouse Events and Control: DoubleClick Command.
Behavior: The DoubleClick command locates an element within the DOM and simulates a double-click event at the found location.
Parameters: A property list containing a required WebElement Identifier and an optional WaitFor property. Alternatively, you can provide a property list that contains a WebLocation Identifier, in which case a WaitFor property is irrelevant.
You can also pass multiple WebElement Identifiers, in which case, each should be included as a separate property list. When you pass more than one WebElement, Eggplant Functional searches for them in the order you list them in the command. If you include WaitFor properties in multiple property lists, SenseTalk uses only the longest WaitFor value for the entire command. That is, it doesn't apply that property multiple times.
Syntax:
DoubleClick { identifierType: value {, waitFor: duration} }
DoubleClick { objectType: "webLocation", x: valueX , y: valueY }
DoubleClick { identifierType: value {, waitFor: duration} } {, { identifierType2: value2 {, waitFor: duration2} }, ... }
Example:
DoubleClick {webName:"TestPlant"}
Example:
Doubleclick {webName:"Testplant",waitFor:20}
RightClick Command
This code definition explains the use of the RightClick command for WebDriver connections. For information about using this command for image-based scripting, see Mouse Events and Control: RightClick Command.
Behavior: The RightClick command locates an element within the DOM and simulates a right-click event at the found location.
Parameters: A property list containing a required WebElement Identifier and an optional WaitFor property. Alternatively, you can provide a property list that contains a WebLocation Identifier, in which case a WaitFor property is irrelevant.
You can also pass multiple WebElement Identifiers, in which case, each should be included as a separate property list. When you pass more than one WebElement, Eggplant Functional searches for them in the order you list them in the command. If you include WaitFor properties in multiple property lists, SenseTalk uses only the longest WaitFor value for the entire command. That is, it doesn't apply that property multiple times.
Syntax:
RightClick { identifierType: value {, waitFor: duration} }
RightClick { objectType: "webLocation", x: valueX , y: valueY }
RightClick { identifierType: value {, waitFor: duration} } {, { identifierType2: value2 {, waitFor: duration2} }, ... }
Example:
RightClick {WebLinkText:"Home Lending"}
Example:
rightClick {objectType:"webLocation", x:247, y:108}
Example:
RightClick {WebCSSSelector:"div>a[data-pt-name=share_fb]",waitFor:10}
MoveTo Command
This code definition explains the use of the MoveTo command for WebDriver connections. For information about using this command for image-based scripting, see Mouse Events and Control: MoveTo Command.
Behavior: The MoveTo command locates an element within the DOM and moves the cursor on the web page to the location where the element is displayed. If the WebElement is not in view, this command scrolls it into view. You can use this command to perform hover actions such as opening pop-up menus.
Parameters: A property list containing a required WebElement Identifier and an optional WaitFor property. Alternatively, you can provide a property list that contains a WebLocation Identifier, in which case a WaitFor property is irrelevant.
You can also pass multiple WebElement Identifiers, in which case, each should be included as a separate property list. When you pass more than one WebElement, Eggplant Functional searches for them in the order you list them in the command. If you include WaitFor properties in multiple property lists, SenseTalk uses only the longest WaitFor value for the entire command. That is, it doesn't apply that property multiple times.
Syntax:
MoveTo { identifierType: value {, waitFor: duration} }
MoveTo { objectType: "webLocation", x: valueX , y: valueY }
MoveTo { identifierType: value {, waitFor: duration} } {, { identifierType2: value2 {, waitFor: duration2} }, ... }
Example:
moveTo {webPartialLinkText:"TestPlant"}
Example:
MoveTo {WebCSSSelector:"div[class*=icon-savings-small]",WaitFor:10}
Example:
Moveto {WebID:"sign-in-button"} // Scrolls the element into the viewport by first locating it in the DOM
Click "SignInButton" // Uses an image search to confirm the button appears correctly in the UI and then clicks on it
Example:
set elementsList to FindElements(webTagName:"h3")
repeat with each element in elementsList
moveTo element
WaitFor 2, "CommonIcon"
end repeat
Drag Command
This code definition explains the use of the Drag command for WebDriver connections. For information about using this command for image-based scripting, see Mouse Events and Control: Drag Command.
Behavior: The Drag command locates an element within the DOM, moves the cursor on the web page to the location where the element is displayed, then simulates a mouse-down action. Typically, you would use the Drag command followed by the Drop command, which moves the cursor to a new location and releases the mouse-down.
Parameters: A property list containing a required WebElement Identifier and an optional WaitFor property. Alternatively, you can provide a property list that contains a WebLocation Identifier, in which case a WaitFor property is irrelevant.
You can also pass multiple WebElement Identifiers, in which case, each should be included as a separate property list. When you pass more than one WebElement, Eggplant Functional searches for them in the order you list them in the command. If you include WaitFor properties in multiple property lists, SenseTalk uses only the longest WaitFor value for the entire command. That is, it doesn't apply that property multiple times.
Syntax:
Drag { identifierType: value {, waitFor: duration} }
Drag { objectType: "webLocation", x: valueX , y: valueY }
Drag { identifierType: value {, waitFor: duration} } {, { identifierType2: value2 {, waitFor: duration2} }, ... }
Example:
drag {webTagName:"H1"}
drop {WebtagName:"H2"}
Drop Command
This code definition explains the use of the Drop command for WebDriver connections. For information about using this command for image-based scripting, see Mouse Events and Control: Drop Command.
Behavior: The Drop command locates an element within the DOM, moves the cursor on the web page to the location where the element is displayed, then simulates a mouse-up action. During the move, the mouse stays in its initial state, either up or down. Typically, you would use the Drop command after the Drag command, which sets the cursor location and simulates a mouse-down action.
Parameters: A property list containing a required WebElement Identifier and an optional WaitFor property. Alternatively, you can provide a property list that contains a WebLocation Identifier, in which case a WaitFor property is irrelevant.
You can also pass multiple WebElement Identifiers, in which case, each should be included as a separate property list. When you pass more than one WebElement, Eggplant Functional searches for them in the order you list them in the command. If you include WaitFor properties in multiple property lists, SenseTalk uses only the longest WaitFor value for the entire command. That is, it doesn't apply that property multiple times.
Syntax:
Drop { identifierType: value {, waitFor: duration} }
Drop { objectType: "webLocation", x: valueX , y: valueY }
Drop { identifierType: value {, waitFor: duration} } {, { identifierType2: value2 {, waitFor: duration2} }, ... }
Example:
drop {webTagName:"H3"}