Skip to content

Instantly share code, notes, and snippets.

@lotosotol
Last active August 29, 2015 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lotosotol/5f29ad4cfb76cf5bce36 to your computer and use it in GitHub Desktop.
Save lotosotol/5f29ad4cfb76cf5bce36 to your computer and use it in GitHub Desktop.
Selenium.Lecture_68
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
public class javaScriptExecutor {
public static void main(String[] args) throws InterruptedException {
//running Firefox browser under "selenium1" profile:
ProfilesIni listprofiles = new ProfilesIni();
FirefoxProfile profile = listprofiles.getProfile("selenium1");
WebDriver driver = new FirefoxDriver(profile);
driver.navigate().to("http://www.w3schools.com/js/tryit.asp?filename=tryjs_event_onclick3");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);
Thread.sleep(2000L);
//switching to the IFrame to work with it's elements:
driver.switchTo().frame("iframeResult");
//driver.findElement(By.xpath("//h1")).click(); //this works, disabled in order to test the method below
((JavascriptExecutor) driver).executeScript("changeText(this)");
Thread.sleep(3000L);
driver.close();
System.out.println("DONE!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment