-
Notifications
You must be signed in to change notification settings - Fork 0
execute_script
Executes JavaScript in the context of the currently selected frame or window.
Web, Mobile Web, Mobile Native or any other Web Driver implementation which implements Execute Script.
Mobile Native support is limited by Appium capabilities and implemnetaions.
| Property | Description |
|---|---|
| argument | Plugin conditions and additional information. |
| onElement | The locator value by which the element will be found. |
| locator | The locator type by which the element will be found. |
Object array to pass into this script.
| Value | Description |
|---|---|
| array | An array of JSON Formatted objects. |
The JavaScript code to execute.
| Value | Description |
|---|---|
| string | A valid JavaScript script. |
https://www.w3.org/TR/webdriver/#execute-script
Can be tested on
Executes script to change an element value, from document level.
{
"action": "ExecuteScript",
"argument": "{document.getElementById('input_enabled').setAttribute('value', 'foo bar')}"
}execute script {document.getElementById('input_enabled').setAttribute('value', 'foo bar')}
var actionRule = new ActionRule
{
Action = PluginsList.ExecuteScript,
Argument = "{document.getElementById('input_enabled').setAttribute('value', 'foo bar')}"
};action_rule = {
"action": "ExecuteScript",
"argument": "{document.getElementById('input_enabled').setAttribute('value', 'foo bar')}"
}var actionRule = {
action: "ExecuteScript",
argument: "{document.getElementById('input_enabled').setAttribute('value', 'foo bar')}"
};ActionRule actionRule = new ActionRule()
.setAction("ExecuteScript")
.setArgument("{document.getElementById('input_enabled').setAttribute('value', 'foo bar')}");Can be tested on
Executes script to click on an element from Action Rule level.
{
"action": "ExecuteScript",
"argument": "{arguments[0].click();}",
"onElement": "click_button",
"locator": "Id"
}execute script {arguments[0].click();} on {click_button} using {id}
var actionRule = new ActionRule
{
Action = PluginsList.ExecuteScript,
Argument = "{arguments[0].click();}",
OnElement = "click_button",
Locator = LocatorsList.Id
};action_rule = {
"action": "ExecuteScript",
"argument": "{arguments[0].click();}",
"onElement": "click_button",
"locator": "Id"
}var actionRule = {
action: "ExecuteScript",
argument: "{arguments[0].click();}",
onElement: "click_button",
locator: "Id"
};ActionRule actionRule = new ActionRule()
.setAction("ExecuteScript")
.setArgument("{arguments[0].click();}")
.setOnElement("click_button")
.setLocator("Id");Can be tested on
Executes script to scroll the page document, from document level with additional arguments.
{
"action": "ExecuteScript",
"argument": "{{$ --src:window.scrollTo(arguments[0], arguments[1]); --args:[0, 100]}}"
}execute script {{$ --src:window.scrollTo(arguments[0], arguments[1]); --args:[0, 100]}}
var actionRule = new ActionRule
{
Action = PluginsList.ExecuteScript,
Argument = "{{$ --src:window.scrollTo(arguments[0], arguments[1]); --args:[0, 100]}}",
};action_rule = {
"action": "ExecuteScript",
"argument": "{{$ --src:window.scrollTo(arguments[0], arguments[1]); --args:[0, 100]}}"
}var actionRule = {
action: "ExecuteScript",
argument: "{{$ --src:window.scrollTo(arguments[0], arguments[1]); --args:[0, 100]}}"
};ActionRule actionRule = new ActionRule()
.setAction("ExecuteScript")
.setArgument("{{$ --src:window.scrollTo(arguments[0], arguments[1]); --args:[0, 100]}}");Can be tested on
Check the element under extraction. This action applies on current element when using ExtractionRules. This action assumes the element already found and will inject it into the script. For an instance, instead of document.findElementById('id').checked=true; you will provide only the part of the script after the '.' - .checked=true; because the element which is now under extraction was already found and will be injected into your code.
// action rule
{
"action": "ExtractFromDom"
}
// extraction rule
{
"onRootElement": "//input[@id='input_selected']",
"onElements": [
{
"key": "inner_text",
"actions": [
{
"action": "ExecuteScript",
"argument": ".checked=false;"
}
]
}
]
}extract from page on {//input[@id='input_selected']}
< column {inner_text}
> execute script {.checked=false;}
// action rule
var actionRule = new ActionRule
{
Action = PluginsList.ExtractFromDom
};
// extraction rule
var extraction = new ExtractionRule
{
OnRootElement = "//input[@id='input_selected']",
OnElements = new[]
{
new ContentEntry
{
Key = "inner_text",
Actions = new[]
{
new ActionRule
{
Action = PluginsList.ExecuteScript,
Argument = ".checked=false;"
}
}
}
}
};# action rule
action_rule = {
"action": "ExtractFromDom"
}
# extraction rule
extraction_rule = {
"onRootElement": "//input[@id='input_selected']",
"onElements": [
{
"key": "inner_text",
"actions": [
{
"action": "ExecuteScript",
"argument": ".checked=false;"
}
]
}
]
}// action rule
actionRule = {
action: "ExtractFromDom"
}
// extraction rule
extractionRule = {
onRootElement: "//input[@id='input_selected']",
onElements: [
{
key: "inner_text",
actions: [
{
action: "ExecuteScript",
argument: ".checked=false;"
}
]
}
]
}// action rule
ActionRule actionRule = new ActionRule().setAction("ExtractFromDom");
// extraction rule
ActionRule actionRule = new ActionRule()
.setAction("ExecuteScript")
.setArgument(".checked=false;");
ContentEntry contentEntry = new ContentEntry().setKey("inner_text").setActions(actionRule);
ExtractionRule extractionRule = new ExtractionRule()
.setRooElementToExtractFrom("//input[@id='input_selected']")
.setOnElements(contentEntry);