List of usage examples for org.openqa.selenium WebDriver getTitle
String getTitle();
From source file:com.mycompany.newseleniumtest.coba.java
public void latihan(String browser) throws InterruptedException { //Instantiate the webdriver object: WebDriver driver = new FirefoxDriver(); JavascriptExecutor jse = (JavascriptExecutor) driver; //Open the web driver.get("http://dev.uangteman.com/admin/"); driver.manage().window().maximize(); Thread.sleep(1500);/*from w w w .j a v a 2 s .co m*/ driver.findElement(By.name("bu_name")).sendKeys("rahmat_cs"); driver.findElement(By.name("bu_passwd")).sendKeys("testing"); driver.findElement(By.cssSelector("button[class='btn btn-orange btn-squared pull-right ladda-button']")) .click(); Thread.sleep(2500); jse.executeScript("window.scrollBy(0,1500)", ""); jse.executeScript("window.scroll(0,1500)", ""); WebElement scroll = driver.findElement(By.xpath( "/html/body/div[2]/div[2]/div/div[2]/div/div/div[3]/div/div[2]/div/form/table/tbody/tr[1]/td[12]/span")); JavascriptExecutor js = (JavascriptExecutor) driver; jse.executeScript( "document.getElementByxpath('/html/body/div[2]/div[2]/div/div[2]/div/div/div[3]/div/div[2]/div/form/table/tbody/tr[1]/td[12]/span').scrollLeft += 250", ""); //Get page title in selenium webdriver String actual = driver.getTitle(); }
From source file:com.mycompany.selenium.SeleniumExample.java
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver"); // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new ChromeDriver(); // System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver"); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();/*from ww w.j av a2s . c om*/ // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.mycompany.seliniumtest.Selenium2Example.java
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "/usr/local/Cellar/geckodriver/geckodriver"); // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. //WebDriver driver = new FirefoxDriver(); //WebDriver driver = new ChromeDriver(); WebDriver driver = new FirefoxDriver(); //WebDriver driver = new HtmlUnitDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();//from w ww.j a v a2 s .c o m // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.nabla.project.fronter.selenium.tests.GoogleSearchSTest.java
License:Open Source License
@Test public void testGoogleSearch() { // try/*from w w w .j a va2s. co m*/ // { // Find the text input element by its name final WebElement element = this.driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Selenium testing tools cookbook"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(this.driver, 10)).until(new ExpectedCondition<Boolean>() { @Override public Boolean apply(final WebDriver d) { return d.getTitle().toLowerCase().startsWith("selenium testing tools cookbook"); } }); // Should see: selenium testing tools cookbook - Google Search // Assert.assertEquals("Selenium testing tools cookbook - Google Search", this.driver.getTitle()); Assert.assertEquals("Selenium testing tools cookbook - Recherche Google", this.driver.getTitle()); /* * } catch (final Error e) * { * // Capture and append Exceptions/Errors * this.verificationErrors.append(e.toString()); * } */ }
From source file:com.openones.auto.selen.Sample01.java
License:Apache License
public static void main(String[] args) { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new FirefoxDriver(); //WebDriver driver = new InternetExplorerDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit();/*from ww w. java 2 s . com*/ // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); // Google's search is rendered dynamically with JavaScript. // Wait for the page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!"); } }); // Should see: "cheese! - Google Search" System.out.println("Page title is: " + driver.getTitle()); //Close the browser driver.quit(); }
From source file:com.pentaho.ctools.cda.MondrianJNDI.java
License:Apache License
/** * ############################### Test Case 4 ############################### * * Test Case Name:// www. ja v a2 s . co m * Query URL * Description: * The test case pretends to validate return data when call query url. * Steps: * 1. Select the option 'Mdx...' * 2. Click in Cache this * 3. Set a period * 4. In the new window, check the schedule * 5. Remove the schedule */ @Test public void tc5_CacheThisSimple_ScheduleIsSetSuccessful() { this.log.info("tc5_CacheThisSimple_ScheduleIsSetSuccessful"); String selectedHours = "21"; /* * ## Step 1 */ Select select = new Select(this.elemHelper.FindElement(driver, By.id("dataAccessSelector"))); select.selectByVisibleText("Mdx Query on SampleData - Jndi"); //wait to render page this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay")); //Check the presented contains WebElement elemStatus = this.elemHelper.FindElement(driver, By.id("status")); assertEquals("Shipped", elemStatus.getAttribute("value")); //Check we have three elements and no more than that String textPaging = this.elemHelper.WaitForElementPresentGetText(driver, By.id("contents_info")); assertEquals("View 1 to 3 of 3 elements", textPaging); /* * ## Step 2 */ //Click in 'Cache this' this.elemHelper.ClickJS(driver, By.id("cachethis")); this.elemHelper.WaitForElementPresenceAndVisible(driver, By.id("dialog")); String questionActual = this.elemHelper.WaitForElementPresentGetText(driver, By.cssSelector("p.dialogTitle")); String questionExpect = "What schedule should this query run on? (advanced)"; assertEquals(questionExpect, questionActual); /* * ## Step 3 */ String parentWindowHandle = driver.getWindowHandle(); Select selectPeriod = new Select(this.elemHelper.FindElement(driver, By.id("periodType"))); selectPeriod.selectByValue("1"); //every day this.elemHelper.FindElement(driver, By.xpath("//input[@id='startAt']")).clear(); this.elemHelper.FindElement(driver, By.xpath("//input[@id='startAt']")).sendKeys(selectedHours); this.elemHelper.FindElement(driver, By.linkText("Ok")).click(); Set<String> listWindows = driver.getWindowHandles(); //wait for popup render this.elemHelper.WaitForNewWindow(driver); listWindows = driver.getWindowHandles(); //Get popup id WebDriver cdaCacheManager = null; Iterator<String> iterWindows = listWindows.iterator(); while (iterWindows.hasNext()) { String windowHandle = iterWindows.next(); cdaCacheManager = driver.switchTo().window(windowHandle); if (cdaCacheManager.getTitle().equals("CDA Cache Manager")) { break; } } //Validate page: //Title String titleCdaCacheManager = cdaCacheManager.getTitle(); assertEquals("CDA Cache Manager", titleCdaCacheManager); //Scheduled queries String subTitleText = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='scheduledQueries']/div")); assertEquals("Scheduled Queries", subTitleText); /* * ## Step 4 */ //Validate Query SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String strToday = sdf.format(new Date()); String queryName = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='lines']/div/div[1]")); String queryParam1 = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='lines']/div/div[2]//dl//dt")); String queryParam2 = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='lines']/div/div[2]//dl//dd")); String queryLExec = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='lines']/div/div[3]")); String queryNExec = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='lines']/div/div[4]")); String queryCron = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='lines']/div/div[5]")); String queryTime = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='lines']/div/div[6]")); String queryStatus = this.elemHelper.WaitForElementPresentGetText(cdaCacheManager, By.xpath("//div[@id='lines']/div/div[7]")); //AssertPopup for execute and delete WebElement delete = this.elemHelper.FindElement(cdaCacheManager, By.xpath("//a/img[@title='Remove Query']")); WebElement execute = this.elemHelper.FindElement(cdaCacheManager, By.xpath("//a/img[@title='Execute Query']")); assertNotNull(execute); assertNotNull(delete); //Validate execution details try { assertEquals("/public/plugin-samples/cda/cdafiles/mondrian-jndi.cda (1)", queryName); assertEquals("status", queryParam1); assertEquals("Shipped", queryParam2); assertThat("Last Execution: " + queryLExec, queryLExec, CoreMatchers.containsString("1970-01-01")); assertThat("Last Execution: " + queryLExec, queryLExec, CoreMatchers.containsString("00:00:00")); assertThat("Next Execution: " + queryNExec, queryNExec, CoreMatchers.containsString(strToday)); assertThat("Next Execution: " + queryNExec, queryNExec, CoreMatchers.containsString(selectedHours + ":00:00")); assertEquals("0 0 21 * * ? *", queryCron); assertEquals("-1", queryTime); assertEquals("Success", queryStatus); } catch (AssertionError ae) { this.log.error(ae.getMessage()); //Remove schedule this.removeFirstSchedule(); //Need guarantee we close everything cdaCacheManager.close(); driver.switchTo().window(parentWindowHandle); //raise the exception fail(ae.getMessage()); } /* * ## Step 5 */ this.removeFirstSchedule(); cdaCacheManager.close(); driver.switchTo().window(parentWindowHandle); assertTrue(driver.getWindowHandles().size() == 1); }
From source file:com.pentaho.ctools.cdf.JFreeChartComponent.java
License:Apache License
/** * ############################### Test Case 4 ############################### * * Test Case Name://from w ww . j av a 2 s .c o m * Preview Chart * Description: * The test case pretends to validate when user press on Zoom a new window * is displayed. * Steps: * 1. Zoom on Bar Chart * 2. Zoom on Pie Chart */ @Test public void tc4_PreviewChart_NewWindowDisplayed() { this.log.info("tc4_PreviewChart_NewWindowDisplayed"); String title = ""; String attriStyle = ""; // ## Step 1 //Check bar title this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); title = this.elemHelper.WaitForElementPresentGetText(driver, By.id("sampleObjectcaptiontitle")); assertTrue(title.equals("Top 10 Customers")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 10); //Check the bar is visible this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); attriStyle = this.elemHelper.GetAttribute(driver, By.xpath("//div[@class='caption-bottom']"), "style"); assertTrue(attriStyle.contains("margin: -42px")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 10); //Click in Zoom this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionzoom']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 10); // NOTE - we have to wait for loading disappear this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay")); WebDriver popup = null; String parentWindowHandle = driver.getWindowHandle(); // save the current window handle. Set<String> setWindows = driver.getWindowHandles(); //wait for popup render this.elemHelper.WaitForNewWindow(driver); setWindows = driver.getWindowHandles(); //Get popup id Iterator<String> windowIterator = setWindows.iterator(); while (windowIterator.hasNext()) { String windowHandle = windowIterator.next(); popup = driver.switchTo().window(windowHandle); if (popup.getTitle().isEmpty()) { break; } } String attrSrcPopup = this.elemHelper.GetAttribute(popup, By.cssSelector("img"), "src"); assertEquals(HttpStatus.SC_OK, HttpUtils.GetResponseCode(attrSrcPopup)); popup.close(); driver = driver.switchTo().window(parentWindowHandle); assertTrue(driver.getWindowHandles().size() == 1); driver.switchTo().defaultContent(); // ## Step 2 //Change to pie chart this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionchartType']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 3); // NOTE - we have to wait for loading disappear this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay")); //Check bar title this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); title = this.elemHelper.WaitForElementPresentGetText(driver, By.id("sampleObjectcaptiontitle")); assertTrue(title.equals("Top 10 Customers")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 3); //Check bar is visible this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); attriStyle = this.elemHelper.GetAttribute(driver, By.xpath("//div[@class='caption-bottom']"), "style"); assertTrue(attriStyle.contains("margin: -42px")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 3); //Zoom this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionzoom']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 3); // NOTE - we have to wait for loading disappear this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay")); parentWindowHandle = driver.getWindowHandle(); // save the current window handle. setWindows = driver.getWindowHandles(); //wait for popup render this.elemHelper.WaitForNewWindow(driver); setWindows = driver.getWindowHandles(); //Get popup id windowIterator = setWindows.iterator(); while (windowIterator.hasNext()) { String windowHandle = windowIterator.next(); popup = driver.switchTo().window(windowHandle); if (popup.getTitle().isEmpty()) { break; } } attrSrcPopup = this.elemHelper.GetAttribute(popup, By.cssSelector("img"), "src"); assertEquals(HttpStatus.SC_OK, HttpUtils.GetResponseCode(attrSrcPopup)); popup.close(); driver.switchTo().window(parentWindowHandle); assertTrue(driver.getWindowHandles().size() == 1); }
From source file:com.pentaho.ctools.cdf.require.JFreeChartComponent.java
License:Apache License
/** * ############################### Test Case 4 ############################### * * Test Case Name:/* w w w . j a va2 s . c o m*/ * Preview Chart * Description: * The test case pretends to validate when user press on Zoom a new window * is displayed. * Steps: * 1. Zoom on Bar Chart * 2. Zoom on Pie Chart */ @Test public void tc4_PreviewChart_NewWindowDisplayed() { this.log.info("tc4_PreviewChart_NewWindowDisplayed"); String title = ""; String attriStyle = ""; /* * ## Step 1 */ //Check bar title this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); title = this.elemHelper.WaitForElementPresentGetText(driver, By.id("sampleObjectcaptiontitle")); assertTrue(title.equals("Top 10 Customers")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 10); //Check the bar is visible this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); attriStyle = this.elemHelper.GetAttribute(driver, By.xpath("//div[@class='caption-bottom']"), "style"); assertTrue(attriStyle.contains("margin: -42px")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 10); //Click in Zoom this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionzoom']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 10); // NOTE - we have to wait for loading disappear this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay")); WebDriver popup = null; String parentWindowHandle = driver.getWindowHandle(); // save the current window handle. Set<String> setWindows = driver.getWindowHandles(); //wait for popup render this.elemHelper.WaitForNewWindow(driver); setWindows = driver.getWindowHandles(); //Get popup id Iterator<String> windowIterator = setWindows.iterator(); while (windowIterator.hasNext()) { String windowHandle = windowIterator.next(); popup = driver.switchTo().window(windowHandle); if (popup.getTitle().isEmpty()) { break; } } String attrSrcPopup = this.elemHelper.GetAttribute(popup, By.cssSelector("img"), "src"); assertEquals(HttpStatus.SC_OK, HttpUtils.GetResponseCode(attrSrcPopup)); popup.close(); driver = driver.switchTo().window(parentWindowHandle); assertTrue(driver.getWindowHandles().size() == 1); driver.switchTo().defaultContent(); /* * ## Step 2 */ //Change to pie chart this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionchartType']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 3); // NOTE - we have to wait for loading disappear this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay")); //Check bar title this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); title = this.elemHelper.WaitForElementPresentGetText(driver, By.id("sampleObjectcaptiontitle")); assertTrue(title.equals("Top 10 Customers")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 3); //Check bar is visible this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); attriStyle = this.elemHelper.GetAttribute(driver, By.xpath("//div[@class='caption-bottom']"), "style"); assertTrue(attriStyle.contains("margin: -42px")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 3); //Zoom this.elemHelper.Click(driver, By.xpath("//div[@class='caption-details']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: -42px", 3); this.elemHelper.Click(driver, By.xpath("//div[@id='sampleObjectcaptionzoom']")); this.elemHelper.WaitForAttributeValue(driver, By.xpath("//div[@class='caption-bottom']"), "style", "margin: 0px", 3); // NOTE - we have to wait for loading disappear this.elemHelper.WaitForElementInvisibility(driver, By.cssSelector("div.blockUI.blockOverlay")); parentWindowHandle = driver.getWindowHandle(); // save the current window handle. setWindows = driver.getWindowHandles(); //wait for popup render this.elemHelper.WaitForNewWindow(driver); setWindows = driver.getWindowHandles(); //Get popup id windowIterator = setWindows.iterator(); while (windowIterator.hasNext()) { String windowHandle = windowIterator.next(); popup = driver.switchTo().window(windowHandle); if (popup.getTitle().isEmpty()) { break; } } attrSrcPopup = this.elemHelper.GetAttribute(popup, By.cssSelector("img"), "src"); assertEquals(HttpStatus.SC_OK, HttpUtils.GetResponseCode(attrSrcPopup)); popup.close(); driver.switchTo().window(parentWindowHandle); assertTrue(driver.getWindowHandles().size() == 1); }
From source file:com.pentaho.ctools.utils.ElementHelper.java
License:Apache License
/** * This method shall wait for the title and return it. The developer can * specify the timeout and pollingTime.//ww w .j a v a 2 s.com * * * @param driver * @param title * @param timeout * @param pollingTime * @return */ public String WaitForTitle(final WebDriver driver, final String title, final Integer timeout, final Integer pollingTime) { this.log.debug("WaitForTitle::Enter"); String returnTitle = ""; driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); ExecutorService executor = null; try { class RunnableObject implements Runnable { private Boolean textIsEquals; public Boolean isTextEquals() { return this.textIsEquals; } @Override public void run() { Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(timeout, TimeUnit.SECONDS) .pollingEvery(pollingTime, TimeUnit.MILLISECONDS); // Wait for element visible this.textIsEquals = wait.until(new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver d) { String currentTitle = driver.getTitle(); return currentTitle != null && currentTitle.contains(title); } }); } } RunnableObject r = new RunnableObject(); executor = Executors.newSingleThreadExecutor(); executor.submit(r).get(timeout + 2, TimeUnit.SECONDS); if (r.isTextEquals()) { // If the text is equals then send the text that we wait for. returnTitle = title; this.log.debug("Wait for text successful!"); } } catch (InterruptedException ie) { this.log.warn("Interrupted Exception"); this.log.warn(ie.toString()); } catch (ExecutionException ee) { if (ee.getCause().getClass().getCanonicalName() .equalsIgnoreCase(TimeoutException.class.getCanonicalName())) { this.log.warn("WebDriver timeout exceeded!"); } else { this.log.warn("Execution Exception"); this.log.warn(ee.toString()); } } catch (java.util.concurrent.TimeoutException cte) { this.log.warn("Thread timeout exceeded!"); this.log.warn(cte.toString()); } catch (Exception e) { this.log.error("Exception"); this.log.catching(e); } if (executor != null) { executor.shutdown(); } driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); this.log.debug("WaitForTitle::Exit"); return returnTitle; }
From source file:com.photon.phresco.Screens.WebDriverBaseScreen.java
License:Apache License
public void accept() throws InterruptedException { // String parentWindowHandle = driver.getWindowHandle(); // save the current window handle. WebDriver popup = null; //String windowname=driver.getWindowHandle(); Set<String> windowname = driver.getWindowHandles(); Iterator<String> window = windowname.iterator(); while (window.hasNext()) { String windowHandle = window.next(); popup = driver.switchTo().window(windowHandle); // driver.switchTo().defaultContent().switchTo().frame("windowHandle"); System.out.println("------------------POP-UP WINDOW NAME---->" + popup.getTitle().toString()); if (popup.getTitle().toString().equalsIgnoreCase("")) { popup.findElement(By.name("OK")).click(); Thread.sleep(5000);//from w w w . j a v a2 s. c om break; } } }