Java Code Examples for org.openqa.selenium.Alert#accept()
The following examples show how to use
org.openqa.selenium.Alert#accept() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidEncapsulateOperation.java From LuckyFrameClient with GNU Affero General Public License v3.0 | 6 votes |
public static String alertOperation(AndroidDriver<AndroidElement> appium, String operation) { String result = ""; Alert alert = appium.switchTo().alert(); switch (operation) { case "alertaccept": alert.accept(); LogUtil.APP.info("�����������ͬ��..."); break; case "alertdismiss": alert.dismiss(); LogUtil.APP.info("�����������ȡ��..."); break; case "alertgettext": result = "��ȡ����ֵ�ǡ�" + alert.getText() + "��"; LogUtil.APP.info("���������ͨ��getText��ȡ����text����...��Text����ֵ:{}��",alert.getText()); break; default: break; } return result; }
Example 2
Source File: WebBaseOpt.java From WebAndAppUITesting with GNU General Public License v3.0 | 6 votes |
/** * 切换到alter,并点击确认框 */ public void clickAlert(String msg) { WebDriverWait webDriverWait = new WebDriverWait(driver, 10); Alert alert; baseOpt.wait(20); // Alert alert = driver.switchTo().alert(); try { // 不稳定,原因待查。还是用上面的吧 // wait and switchTo, Otherwise, throws a TimeoutException alert = webDriverWait.until(ExpectedConditions.alertIsPresent()); } catch (Exception e) { this.screenShot(); LogUtil.info(driver.manage().logs() + "==>alert等待超时!"); alert = driver.switchTo().alert(); // 与waituntil功能重复,但until经常失败,为了增强健壮性才如此写 } if (msg != null) { AssertUtil.assertEquals(alert.getText(), msg, "提示语错误"); } alert.accept(); baseOpt.wait(30); }
Example 3
Source File: BaseListenerTest.java From java-client with Apache License 2.0 | 6 votes |
protected boolean assertThatAlertListenerWorks(EmptyWebDriver driver, TestListener listener, String prefix) { try { Alert alert = driver.switchTo().alert(); alert.accept(); alert.dismiss(); alert.sendKeys("Keys"); assertThat(listener.messages, contains(prefix + "Attempt to accept alert", prefix + "The alert was accepted", prefix + "Attempt to dismiss alert", prefix + "The alert was dismissed", prefix + "Attempt to send keys to alert", prefix + "Keys were sent to alert")); return true; } finally { listener.messages.clear(); } }
Example 4
Source File: ESStoreAddedAssetTestCase.java From product-es with Apache License 2.0 | 5 votes |
private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
Example 5
Source File: DataSourcesTestCase.java From product-cep with Apache License 2.0 | 5 votes |
@Test(groups = "wso2.cep", description = "Verifying XSS Vulnerability in event data sources - driver field") public void testXSSVenerabilityDriverField() throws Exception { boolean isVulnerable = false; // Login driver.get(getLoginURL()); driver.findElement(By.id("txtUserName")).clear(); driver.findElement(By.id("txtUserName")).sendKeys(cepServer.getContextTenant().getContextUser().getUserName()); driver.findElement(By.id("txtPassword")).clear(); driver.findElement(By.id("txtPassword")).sendKeys(cepServer.getContextTenant().getContextUser().getPassword()); driver.findElement(By.cssSelector("input.button")).click(); // Sending request to even-tracer admin service String url = backendURL.substring(0, 22) + "/carbon/ndatasource/validateconnection-ajaxprocessor.jsp?"; List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("dsName", "John")); params.add(new BasicNameValuePair("driver", "<script>alert(1)</script>")); params.add(new BasicNameValuePair("url", "http://abc.com")); params.add(new BasicNameValuePair("username", "John")); params.add(new BasicNameValuePair("dsType", "RDBMS")); params.add(new BasicNameValuePair("dsProviderType", "default")); url += URLEncodedUtils.format(params, "UTF-8"); driver.get(url); try { // Alert appears if vulnerable to XSS attack. Alert alert = driver.switchTo().alert(); alert.accept(); isVulnerable = true; } catch (NoAlertPresentException e) { // XSS vulnerability is not there } Assert.assertFalse(isVulnerable); driver.close(); }
Example 6
Source File: ESStoreOverriddenGlobalPageTestCase.java From product-es with Apache License 2.0 | 5 votes |
private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
Example 7
Source File: ITRenameBucketDuplicate.java From nifi-registry with Apache License 2.0 | 5 votes |
private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
Example 8
Source File: WebDriverTestCase.java From htmlunit with Apache License 2.0 | 5 votes |
/** * Gets the alerts collected by the driver. * Note: it currently works only if no new page has been loaded in the window * @param maxWaitTime the maximum time to wait to get the alerts (in millis) * @param driver the driver * @param alertsLength the expected length of Alerts * @return the collected alerts * @throws Exception in case of problem */ protected List<String> getCollectedAlerts(final long maxWaitTime, final WebDriver driver, final int alertsLength) throws Exception { final List<String> collectedAlerts = new ArrayList<>(); long maxWait = System.currentTimeMillis() + maxWaitTime; while (collectedAlerts.size() < alertsLength && System.currentTimeMillis() < maxWait) { try { final Alert alert = driver.switchTo().alert(); final String text = alert.getText(); collectedAlerts.add(text); alert.accept(); // handling of alerts requires some time // at least for tests with many alerts we have to take this into account maxWait += 100; if (useRealBrowser()) { if (getBrowserVersion().isIE()) { // alerts for real IE are really slow maxWait += 5000; } } } catch (final NoAlertPresentException e) { Thread.sleep(10); } } return collectedAlerts; }
Example 9
Source File: ESStoreAssetOverrideExistingPageTestCase.java From product-es with Apache License 2.0 | 5 votes |
private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
Example 10
Source File: ITCreateBucket.java From nifi-registry with Apache License 2.0 | 5 votes |
private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
Example 11
Source File: ITCreateDuplicateBucket.java From nifi-registry with Apache License 2.0 | 5 votes |
private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
Example 12
Source File: DataSourcesTestCase.java From product-cep with Apache License 2.0 | 5 votes |
@Test(groups = "wso2.cep", description = "Verifying XSS Vulnerability in event data sources - data source name field") public void testXSSVenerabilityNameField() throws Exception { boolean isVulnerable = false; // Login driver.get(getLoginURL()); driver.findElement(By.id("txtUserName")).clear(); driver.findElement(By.id("txtUserName")).sendKeys(cepServer.getContextTenant().getContextUser().getUserName()); driver.findElement(By.id("txtPassword")).clear(); driver.findElement(By.id("txtPassword")).sendKeys(cepServer.getContextTenant().getContextUser().getPassword()); driver.findElement(By.cssSelector("input.button")).click(); // Sending request to even-tracer admin service String url = backendURL.substring(0, 22) + "/carbon/ndatasource/newdatasource.jsp?"; List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("dsName", "RiskScoringDB\"><script>alert(1)</script><example attr=\"")); params.add(new BasicNameValuePair("edit", "true")); url += URLEncodedUtils.format(params, "UTF-8"); driver.get(url); try { // Alert appears if vulnerable to XSS attack. Alert alert = driver.switchTo().alert(); alert.accept(); isVulnerable = true; } catch (NoAlertPresentException e) { // XSS vulnerability is not there } Assert.assertFalse(isVulnerable); driver.close(); }
Example 13
Source File: ITRenameBucket.java From nifi-registry with Apache License 2.0 | 5 votes |
private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
Example 14
Source File: ITDeleteSingleBucket.java From nifi-registry with Apache License 2.0 | 5 votes |
private String closeAlertAndGetItsText() { try { Alert alert = driver.switchTo().alert(); String alertText = alert.getText(); if (acceptNextAlert) { alert.accept(); } else { alert.dismiss(); } return alertText; } finally { acceptNextAlert = true; } }
Example 15
Source File: WebDriverITBase.java From rice with Educational Community License v2.0 | 5 votes |
/** * Accept the javascript alert (clicking OK) * */ protected void acceptAlert() { Alert alert = driver.switchTo().alert(); //update is executed alert.accept(); }
Example 16
Source File: KWSAlert.java From xframium-java with GNU General Public License v3.0 | 4 votes |
@Override public boolean _executeStep( Page pageObject, WebDriver webDriver, Map<String, Object> contextMap, Map<String, PageData> dataMap, Map<String, Page> pageMap, SuiteContainer sC, ExecutionContextTest executionContext ) { try { WebDriverWait alertWait = new WebDriverWait( webDriver, 5 ); Alert currentAlert = alertWait.until( new Function<WebDriver,Alert>(){ @Override public Alert apply( WebDriver t ) { return ExpectedConditions.alertIsPresent().apply( t ); } } ); if ( getContext() != null && !getContext().isEmpty() ) addContext( getContext(), currentAlert.getText(), contextMap, executionContext ); switch( ALERT_TYPE.valueOf( getName() ) ) { case ACCEPT: currentAlert.accept(); break; case DISMISS: currentAlert.dismiss(); break; case SEND_KEYS: currentAlert.sendKeys( getParameterValue( getParameterList().get( 0 ), contextMap, dataMap, executionContext.getxFID() ) + "" ); currentAlert.accept(); break; default: log.warn( "Unhandled Alert Type: " + getName() ); } } catch( NoAlertPresentException e ) { return false; } return true; }
Example 17
Source File: TestUserManagerFunction.java From base-framework with Apache License 2.0 | 4 votes |
@Test public void doTest() { s.open("/"); //通过点击,进入功能模块 s.click(By.id("SJDK3849CKMS3849DJCK2039ZMSK0003")); s.click(By.id("SJDK3849CKMS3849DJCK2039ZMSK0004")); //获取table中的所有操作前的tr List<WebElement> beforeTrs = s.findElements(By.xpath("//table//tbody//tr")); //断言所有tr是否等于期望值 assertEquals(beforeTrs.size(), 5); //打开添加页面 s.click(By.xpath("//a[@href='/base-curd/account/user/read']")); //填写表单 s.type(By.xpath("//form[@id='create-user-form']//input[@name='username']"), "admin"); s.type(By.xpath("//form[@id='create-user-form']//input[@name='realname']"), "maurice.chen"); s.type(By.xpath("//form[@id='create-user-form']//input[@name='password']"), "admin"); s.type(By.xpath("//form[@id='create-user-form']//input[@name='confirmPassword']"), "admin"); s.getSelect(By.xpath("//form[@id='create-user-form']//select[@name='state']")).selectByValue("1"); s.type(By.xpath("//form[@id='create-user-form']//input[@name='email']"), "[email protected]"); //选中所有复选框 s.check(s.findElement(By.id("selectAll"))); //提交表单,页面验证不通过 s.click(By.xpath("//div[@class='panel-footer']//button[@type='submit']")); //设置最后的一个值 s.type(By.xpath("//form[@id='create-user-form']//input[@name='username']"), "test_admin"); //验证通过,提交表单 s.click(By.xpath("//div[@class='panel-footer']//button[@type='submit']")); //返回成功信息 String message = s.findElement(By.className("alert")).getText(); assertTrue(message.contains("新增成功")); //获取table中的所有操作前的tr List<WebElement> aflterTrs = s.findElements(By.xpath("//table//tbody//tr")); //添加成功后应该比开始的记录多一条 assertEquals(aflterTrs.size(), beforeTrs.size() + 1); //点击编辑功能 s.findElement(By.xpath("//table//tbody//tr//*[text()='test_admin']//..//a")).click(); //填写表单 s.type(By.xpath("//form[@id='update-user-form']//input[@name='realname']"), "test_realname"); s.getSelect(By.xpath("//form[@id='update-user-form']//select[@name='state']")).selectByValue("2"); //选中所有复选框 for (WebElement element : s.findElements(By.name("groupId"))) { s.uncheck(element); } //提交表单 s.click(By.xpath("//div[@class='panel-footer']//button[@type='submit']")); //返回成功信息 message = s.findElement(By.className("alert")).getText(); assertTrue(message.contains("修改成功")); aflterTrs = s.findElement(By.tagName("table")).findElements(By.xpath("//tbody//tr")); //添加成功后应该比开始的记录多一条 assertEquals(aflterTrs.size(), beforeTrs.size() + 1); //选中删除的记录 s.check(By.xpath("//table//tbody//tr//*[text()='test_admin']//..//input")); //提交删除表单 s.click(By.xpath("//div[@class='panel-footer']//*[@type='submit']")); Alert alert = s.getDriver().switchTo().alert(); alert.accept(); //返回成功信息 message = s.findElement(By.className("alert")).getText(); assertTrue(message.contains("删除1条信息成功")); aflterTrs = s.findElement(By.tagName("table")).findElements(By.xpath("//tbody//tr")); //删除成功后应该刚刚开始的记录一样 assertEquals(aflterTrs.size(), beforeTrs.size()); //打开查询框 s.click(By.xpath("//div[@class='panel-footer']//*[@data-toggle='modal']")); s.waitForVisible(By.id("search-modal")); //设置查询条件值 s.type(By.id("filter_RLIKES_username"), "admin"); s.type(By.id("filter_RLIKES_realname"), "maurice"); s.getSelect(By.name("filter_EQI_state")).selectByValue("1"); s.type(By.id("filter_RLIKES_email"), "es"); //查询 s.click(By.xpath("//div[@class='modal-footer']//button[@type='submit']")); aflterTrs = s.findElement(By.tagName("table")).findElements(By.xpath("//tbody//tr")); //断言查询后的记录数 assertEquals(aflterTrs.size(), 1); }
Example 18
Source File: HandleModal.java From opentest with MIT License | 4 votes |
@Override public void run() { super.run(); String perform = this.readStringArgument("perform"); this.waitForAsyncCallsToFinish(); WebDriverWait wait = new WebDriverWait(this.driver, this.getExplicitWaitSec()); wait.until(ExpectedConditions.alertIsPresent()); Alert alert = driver.switchTo().alert(); String text; switch (perform.toLowerCase()) { case "accept": alert.accept(); break; case "dismiss": alert.dismiss(); break; case "gettext": text = alert.getText(); this.writeOutput("text", text); break; case "sendkeys": text = this.readStringArgument("text", null); String key = this.readStringArgument("key", null); if (text != null) { alert.sendKeys(text); } else if (key != null) { String keyString = Keys.valueOf(key.toUpperCase()).toString(); alert.sendKeys(keyString); } else { throw new RuntimeException("Neither the \"text\" argument, nor the \"key\" argument were provided."); } break; default: throw new RuntimeException( "The \"perform\" argument must have one of the following values: accept, " + "authenticate, dismiss, getText, sendKeys, setCredentials."); } }
Example 19
Source File: InquiryAftBase.java From rice with Educational Community License v2.0 | 4 votes |
protected void testInquiry() throws Exception { selectFrameIframePortlet(); waitAndTypeByName(CRITERIA_NAME+"[number]", "a1"); waitAndClickByXpath("//*[@alt='Direct Inquiry']"); selectTopFrame(); Thread.sleep(5000); gotoLightBox(); SeleneseTestBase.assertEquals("Travel Account Inquiry", getTextByXpath("//h1/span").trim()); assertElementPresentByLinkText("a1"); selectTopFrame(); waitAndClickByXpath("//div[@class='fancybox-item fancybox-close']"); selectFrameIframePortlet(); waitAndClickByXpath("//button[contains(text(),'Clear Values')]"); //-----------------------------Code will not work as page has freemarker exceptions------------------------ Thread.sleep(2000); waitAndClickByXpath("//*[@alt='Direct Inquiry']"); Alert a1 = driver.switchTo().alert(); Assert.assertEquals("Please enter a value in the appropriate field.", a1.getText()); a1.accept(); switchToWindow("null"); selectFrameIframePortlet(); //No Direct Inquiry Option for Fiscal Officer. waitAndTypeByName(CRITERIA_NAME+"[foId]", "1"); waitAndClickByXpath("//*[@id='u229']"); selectTopFrame(); Thread.sleep(5000); gotoLightBox(); Assert.assertEquals("Fiscal Officer Lookup", getTextByXpath("//h1/span").trim()); Assert.assertEquals("1", waitAndGetAttributeByName(CRITERIA_NAME + "[id]", "value")); waitAndClickByXpath(SEARCH_BUTTON_XPATH); selectFrameIframePortlet(); selectOptionByName(CRITERIA_NAME+"[extension.accountTypeCode]", "CAT"); waitAndClickByXpath("//fieldset[@id='u232_fieldset']/input[@alt='Search Field']"); selectTopFrame(); Thread.sleep(5000); gotoLightBox(); Assert.assertEquals("Travel Account Type Lookup", getTextByXpath("//h1/span").trim()); Assert.assertEquals("CAT", waitAndGetAttributeByName(CRITERIA_NAME + "[accountTypeCode]", "value")); waitAndClickByXpath(SEARCH_BUTTON_XPATH); selectFrameIframePortlet(); }
Example 20
Source File: Edition059_Picker_Wheel.java From appiumpro with Apache License 2.0 | 4 votes |
@Test public void testPicker() { // get to the picker view wait.until(ExpectedConditions.presenceOfElementLocated(pickerScreen)).click(); // find the picker elements List<WebElement> pickerEls = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(pickers)); // use the sendKeys method to set the picker wheel values directly pickerEls.get(0).sendKeys("March"); pickerEls.get(1).sendKeys("6"); // trigger the API call to get date info driver.findElement(learnMoreBtn).click(); // verify info was retrieved for the correct date wait.until(ExpectedConditions.alertIsPresent()); Alert alert = driver.switchTo().alert(); Assert.assertThat(alert.getText(), Matchers.containsString("On this day (3/6) in")); // clear the alert alert.accept(); wait.until(ExpectedConditions.not(ExpectedConditions.alertIsPresent())); // use the selectPickerWheelValue method to move to the next value in the 'month' wheel HashMap<String, Object> params = new HashMap<>(); params.put("order", "next"); params.put("offset", 0.15); params.put("element", ((RemoteWebElement) pickerEls.get(0)).getId()); driver.executeScript("mobile: selectPickerWheelValue", params); // and move to the previous value in the 'day' wheel params.put("order", "previous"); params.put("element", ((RemoteWebElement) pickerEls.get(1)).getId()); driver.executeScript("mobile: selectPickerWheelValue", params); // trigger the API call to get date info driver.findElement(learnMoreBtn).click(); // and finally verify info was retrieved for the correct date (4/5) wait.until(ExpectedConditions.alertIsPresent()); alert = driver.switchTo().alert(); Assert.assertThat(alert.getText(), Matchers.containsString("On this day (4/5) in")); alert.accept(); }