Is JavaScriptExecutor works for Appium?

Is JavaScriptExecutor works for Appium ?If Yes, How it works and execute the scripts ?
Please let me know if any one knows !!!

Thanks & Regards,
Bhaskar.

2 Likes

Hi Bhaskar,

I have used JavaScriptExecutor with a hybrid app as below:

js = (JavascriptExecutor) driver;
js.executeScript(“window.scrollTo(0,0)”);

driver is a WebDriver instance.

Thanks,
Sujata

Hi @sujata_kalluri,
Thanks for your reply.!!!

apparently, swipe and scroll these two are only working with JavascriptExecutor , still any actions could be done with that?

Thanks,
Bhaskar.

What ever you use for WebDriver can use for Appium too, I use JavaScriptExecuter many times in my framework and working awesome

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$(’#scroller’).val(’" + data + “’)”);

((JavascriptExecutor) driver)
.executeScript(“SomText.Config.isTestOrder=true;”);

Hi,

What other actions are you looking for?
So far I have used only scroll.

Thanks,
Sujata

Hi @ASYB ,

Could you please explain us more about JSExeutor and how it works, that will help us more.

Thank you in advance,
Bhaskar,

JSExecuter is use to run Javascript,
eg :
jsExecuter = (JavaScriptExecutor)driver;
jsExecuter.ExecuteScript(“any JavaScript”)
For JavaScript, text that we will use as java script, is fully a java script code . If we need a function output from that java script, we have to use ” return” before the script. For example, if we want title
jsExecuter.ExecuteScript(“return document.title”);

Sample JSexecuter …

ExpectedCondition expectation = new ExpectedCondition() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) driver).executeScript(
“return document.readyState”).equals(“complete”);
}

((JavascriptExecutor) driver)
.executeScript(“function pageloadingtime()” + “{”
+ “return ‘Page has completely loaded’” + "}
+ “return (window.onload=pageloadingtime());”);

((JavascriptExecutor) driver)
.executeScript(“window.AutomationTesting = true;”);

2 Likes

Please refer to http://xxv5.cba.pl/a5715.html

Hey folks

Do you guys have link to download the jar org.openqa.selenium.android which has JavascriptExecutor class implemented…I dont find one.

When i Use the below snippet

js = (JavascriptExecutor) driver;
js.executeScript(“window.scrollTo(x,y)”);

x,y being the location of the element i want to scroll. It says “Can’t find variable: window”.

Appium - 1.5.3
App Type - Native App
OS - IOS - Ipad

Any Help is Appreaciated :slight_smile:

Hi,
How do we use JavaScriptExecutor with a hybrid app for sendKeys method?
Thanks,
Yusuf

Hello ASYB
What about using java script executor for changing attribute value like “visible” to be with true rather than false?!
I have tried this piece line of code:
JavascriptExecutor js = (JavascriptExecutor) driver;
//WebElement redFamily = driver.findElementByXPath("//XCUIElementTypeStaticText[@name=‘Red+ / FAMILIE’]");
//js.executeScript(“arguments[0].setAttribute(‘visible’ = ‘true’)”,redFamily);

But return an error Appium not implement this method :S :frowning: ??

1 Like