List of usage examples for org.openqa.selenium WebDriver switchTo
TargetLocator switchTo();
From source file:browsermator.com.CloseCurrentTabOrWindowAction.java
@Override public void RunAction(WebDriver driver) { try {/*from w w w.j a va 2 s .com*/ // driver.findElement(By.cssSelector("html")).sendKeys(Keys.chord(Keys.CONTROL, "w")); // Actions actions = new Actions(driver); // actions.keyDown(Keys.CONTROL).sendKeys("w").keyUp(Keys.CONTROL).build().perform(); ((JavascriptExecutor) driver).executeScript("close();"); for (String winHandle : driver.getWindowHandles()) { driver.switchTo().window(winHandle); } this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.DownArrowKeyAction.java
@Override public void RunAction(WebDriver driver) { try {/*from w w w . j a v a 2 s . c o m*/ WebElement element = driver.switchTo().activeElement(); element.sendKeys(Keys.ARROW_DOWN); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.EnterKeyAction.java
@Override public void RunAction(WebDriver driver) { try {/*w w w .j a va 2 s. c o m*/ WebElement element = driver.switchTo().activeElement(); element.sendKeys(Keys.RETURN); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.EscapeKeyAction.java
@Override public void RunAction(WebDriver driver) { try {//from w ww.j a v a 2s . c o m WebElement element = driver.switchTo().activeElement(); element.sendKeys(Keys.ESCAPE); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.LeftArrowKeyAction.java
@Override public void RunAction(WebDriver driver) { try {//from ww w .ja va 2 s . c om WebElement element = driver.switchTo().activeElement(); element.sendKeys(Keys.ARROW_LEFT); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.NextTabAction.java
@Override public void RunAction(WebDriver driver) { try {/*from w w w.j av a 2 s .co m*/ // Actions actions = new Actions(driver); String current_tab_handle = driver.getWindowHandle(); driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, Keys.TAB)); // actions.keyDown(Keys.CONTROL).sendKeys(Keys.TAB).keyUp(Keys.CONTROL).build().perform(); Set<String> tab_handles = driver.getWindowHandles(); int current_tab_index = 0; int number_of_tabs = tab_handles.size(); int tabs_counted = 1; for (String handle : tab_handles) { if (handle.equals(current_tab_handle)) { if (tabs_counted == number_of_tabs) { // last tab current_tab_index = 0; } else { current_tab_index = tabs_counted; } } tabs_counted++; } driver.switchTo().window(tab_handles.toArray()[current_tab_index].toString()); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.OpenNewTabAction.java
@Override public void RunAction(WebDriver driver) { try {//from w ww. jav a 2 s . com ((JavascriptExecutor) driver).executeScript("window.open('about:blank', '_blank');"); //driver.findElement(By.cssSelector("body")).sendKeys(Keys.chord(Keys.CONTROL, "t")); // Actions actions = new Actions(driver); // actions.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform(); Set<String> tab_handles = driver.getWindowHandles(); int number_of_tabs = tab_handles.size(); int new_tab_index = number_of_tabs - 1; driver.switchTo().window(tab_handles.toArray()[new_tab_index].toString()); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.RightArrowKeyAction.java
@Override public void RunAction(WebDriver driver) { try {//from ww w. j av a2 s . com WebElement element = driver.switchTo().activeElement(); element.sendKeys(Keys.ARROW_RIGHT); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.SwitchToTabOrWindowAction.java
@Override public void RunAction(WebDriver driver) { int int_index = 0; if (this.Variable1 != "") { int_index = Integer.parseInt(this.Variable1); }/*w w w . j a va 2 s . c o m*/ try { ArrayList<String> tabs_windows = new ArrayList<String>(driver.getWindowHandles()); driver.switchTo().window(tabs_windows.get(int_index)); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }
From source file:browsermator.com.UpArrowKeyAction.java
@Override public void RunAction(WebDriver driver) { try {// w w w. j a va 2s. c o m WebElement element = driver.switchTo().activeElement(); element.sendKeys(Keys.ARROW_UP); this.Pass = true; } catch (Exception ex) { this.Pass = false; } }