How to Change the value of Applet using JavaScriptExecutor using Selenium Webdriver? – Learn By Example
Please refer example site used in this blog LINK
public class appletTestingWebdriver { public static void main(String[] args) throws InterruptedException { WebDriver myTestDriver = new FirefoxDriver(); myTestDriver.manage().window().maximize(); myTestDriver.navigate().to("http://tinyurl.com/2v5pzuh"); Thread.sleep(5000L); JavascriptExecutor js = (JavascriptExecutor) myTestDriver; js.executeScript("document.jsap.setText(document.forms[0].txt1.value);"); } }
How to do JavaScript and Applet interaction using Selenium Webdriver? – Learn by example
How to do JavaScript and Applet interaction using Selenium Webdriver?
How to Change the value of Applet using JavaScriptExecutor using Selenium Webdriver?
Please refer Example Website used in this example LINK
In above example image java applet have one counter increment button and one receiver label which displays incremented counter value.
We make program which perform same function as by Click to increment counter button.
public class AppletExample { public static void main(String[] args) throws InterruptedException { WebDriver myTestDriver = new FirefoxDriver(); myTestDriver.manage().window().maximize(); myTestDriver.navigate().to("http://tinyurl.com/ct697n7"); JavascriptExecutor js = (JavascriptExecutor) myTestDriver; js.executeScript("receiver.incrementCounter();"); js.executeScript("receiver.incrementCounter();"); js.executeScript("receiver.incrementCounter();"); js.executeScript("receiver.incrementCounter();"); js.executeScript("receiver.incrementCounter();"); js.executeScript("receiver.incrementCounter();"); } }
Learn by example – how to use javascriptexecutor for JavaScript in Selenium tests? – Selenium webdriver
Did you know you can execute JavaScript code inside a Selenium test? Here is how you can accomplish this using the WebDriver
object:
display current date on browser
import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class displayDate { public static void main(String[] args) throws InterruptedException { WebDriver driver; driver = new FirefoxDriver(); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.write(Date());"); } }
display current date on Alert box
import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class displayDate { public static void main(String[] args) throws InterruptedException { WebDriver driver; driver = new FirefoxDriver(); JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("alert(Date());"); } }
You must be logged in to post a comment.