List of usage examples for org.openqa.selenium WebElement isEnabled
boolean isEnabled();
From source file:com.consol.citrus.cucumber.step.runner.selenium.SeleniumStepsTest.java
License:Apache License
@Test public void testShouldDisplay() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("button"); when(webDriver.findElement(any(By.class))).thenAnswer(invocation -> { By select = (By) invocation.getArguments()[0]; Assert.assertEquals(select.getClass(), By.ByName.class); Assert.assertEquals(select.toString(), "By.name: foo"); return element; });/*from w w w . j a v a2 s . c o m*/ steps.setBrowser("seleniumBrowser"); steps.should_display("name", "foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate() instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) ((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate(); Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof FindElementAction); Assert.assertEquals(((FindElementAction) action).getProperty(), "name"); Assert.assertEquals(((FindElementAction) action).getPropertyValue(), "foo"); }
From source file:com.consol.citrus.selenium.actions.FindElementAction.java
License:Apache License
/** * Validates found web element with expected content. * @param element/*w ww . ja va 2 s .co m*/ * @param browser * @param context */ protected void validate(WebElement element, SeleniumBrowser browser, TestContext context) { validateElementProperty("tag-name", tagName, element.getTagName(), context); validateElementProperty("text", text, element.getText(), context); Assert.isTrue(displayed == element.isDisplayed(), String.format( "Selenium web element validation failed, " + "property 'displayed' expected '%s', but was '%s'", displayed, element.isDisplayed())); Assert.isTrue(enabled == element.isEnabled(), String.format( "Selenium web element validation failed, " + "property 'enabled' expected '%s', but was '%s'", enabled, element.isEnabled())); for (Map.Entry<String, String> attributeEntry : attributes.entrySet()) { validateElementProperty(String.format("attribute '%s'", attributeEntry.getKey()), attributeEntry.getValue(), element.getAttribute(attributeEntry.getKey()), context); } for (Map.Entry<String, String> styleEntry : styles.entrySet()) { validateElementProperty(String.format("css style '%s'", styleEntry.getKey()), styleEntry.getValue(), element.getCssValue(styleEntry.getKey()), context); } }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Broadband_Util.java
protected void clickOnRadioRM50() { boolean breakIt; while (true) { breakIt = true;//from w w w.j a v a 2s . c o m try { // Put email id on text field as it can not be blank //*[@id="reloadForm__email"] WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); //js1.executeScript("window.scrollBy(0,400)", ""); //*[@id="prepaidReloadForm"]/ul/li[2]/label/div WebElement radio = getDriver() .findElement(By.xpath("//*[@id='prepaidReloadForm']/ul/li[4]/label/div")); radio.click(); // now select check box to accept license agreement WebElement checkbox = getDriver().findElement(By.xpath("//*[@id='prepaidReloadForm']/label/div")); checkbox.click(); // click on proceed button after selecting radio button and check box // WebElement elementproceed=getDriver().findElement(By.xpath("//*[@id='proceedBtn']")); //*[@id="proceedBtn"] WebElement proceed = (new WebDriverWait(getDriver(), 1000)) .until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='proceedBtn']"))); proceed.click(); waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); } catch (Exception e) { System.out.println(e); breakIt = false; e.printStackTrace(); log.error("Fail : Failed to Reload amount."); System.exit(0); } if (breakIt) { break; } } //while ends }
From source file:com.digi.selenium.util.BillNReload.Bill_n_Reload_Prepaid_Util.java
protected void clickOnRadioRM50() { try {/*from ww w .ja va 2s .c om*/ // Put email id on text field as it can not be blank //*[@id="reloadForm__email"] WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); js1.executeScript("window.scrollBy(0,400)", ""); //*[@id="prepaidReloadForm"]/ul/li[2]/label/div WebElement radio = getDriver().findElement(By.xpath("//*[@id='prepaidReloadForm']/ul/li[4]/label/div")); radio.click(); // now select check box to accept license agreement WebElement checkbox = getDriver().findElement(By.xpath("//*[@id='prepaidReloadForm']/label/div")); checkbox.click(); // click on proceed button after selecting radio button and check box // WebElement elementproceed=getDriver().findElement(By.xpath("//*[@id='proceedBtn']")); //*[@id="proceedBtn"] WebElement proceed = (new WebDriverWait(getDriver(), 1000)) .until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='proceedBtn']"))); proceed.click(); waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); } catch (Exception e) { System.out.println(e); e.printStackTrace(); log.error("Fail : Failed to Reload amount."); System.exit(0); } }
From source file:com.digi.selenium.util.common.PageNavigation.java
protected void clickOnRadio10() throws InterruptedException { // try {//from ww w.j a va2s . c o m WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); //Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); js1.executeScript("window.scrollBy(0,400)", ""); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/ul/li[2]/label/div", 5).click(); log.info("Success : Radio Button of amonut 10 is clicked"); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/label/div", 5).click(); log.info("Success : checkbox is clicked"); tryToClickElementByXPath("//*[@id='proceedBtn']", 5).click(); log.info("Success : Proceed Button is clicked"); waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); /*}catch(Exception e) { log.error("Fail : Failed to process reload of amount 10."); shutDown(); }*/ }
From source file:com.digi.selenium.util.common.PageNavigation.java
protected void clickOnRadio30() throws InterruptedException { // try {//from w w w . ja va 2 s . c o m WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); //Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); js1.executeScript("window.scrollBy(0,400)", ""); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/ul/li[3]/label/div", 5).click(); log.info("Success : Radio Button of amonut 30 is clicked"); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/label/div", 5).click(); log.info("Success : checkbox is clicked"); tryToClickElementByXPath("//*[@id='proceedBtn']", 5).click(); log.info("Success : Proceed Button is clicked"); waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); /*}catch(Exception e) { log.error("Fail : Failed to process reload of amount 30."); shutDown(); }*/ }
From source file:com.digi.selenium.util.common.PageNavigation.java
protected void clickOnRadio50() throws InterruptedException { // try {// w w w. j a v a 2 s .co m WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); //Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); js1.executeScript("window.scrollBy(0,400)", ""); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/ul/li[4]/label/div", 5).click(); log.info("Success : Radio Button of amonut 30 is clicked"); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/label/div", 5).click(); log.info("Success : checkbox is clicked"); tryToClickElementByXPath("//*[@id='proceedBtn']", 5).click(); log.info("Success : Proceed Button is clicked"); waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); /*}catch(Exception e) { log.error("Fail : Failed to process reload of amount 30."); shutDown(); }*/ }
From source file:com.digi.selenium.util.common.PageNavigation.java
protected void clickOnRadio100() throws InterruptedException { // try {/* w ww . j av a2s .c om*/ WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); //Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); js1.executeScript("window.scrollBy(0,400)", ""); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/ul/li[1]/label/div", 5).click(); log.info("Success : Radio Button of amonut 100 is clicked"); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/label/div", 5).click(); log.info("Success : checkbox is clicked"); tryToClickElementByXPath("//*[@id='proceedBtn']", 5).click(); log.info("Success : Proceed Button is clicked"); /* WebElement proceed=(new WebDriverWait(driver, 1000)).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='proceedBtn']"))); proceed.click();*/ waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); /*}catch(Exception e) { log.error("Fail : Failed to process reload of amount 100."); shutDown(); }*/ }
From source file:com.digi.selenium.util.common.PageNavigation.java
protected void clickOnRadioRM10() throws InterruptedException { // try {//from w w w. j a v a2 s. c o m WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); //Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); js1.executeScript("window.scrollBy(0,400)", ""); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/ul/li[2]/label/div", 5).click(); log.info("Success : Radio Button of amonut 10 is clicked"); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/label/div", 5).click(); log.info("Success : checkbox is clicked"); tryToClickElementByXPath("//*[@id='proceedBtn']", 5).click(); log.info("Success : Proceed Button is clicked"); waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); /*}catch(Exception e) { log.error("Fail : Failed to process reload of amount 10."); shutDown(); }*/ }
From source file:com.digi.selenium.util.common.PageNavigation.java
protected void clickOnRadioRM30() throws InterruptedException { // try {//from w w w . j a va 2 s .com WebElement emailtxt = getDriver().findElement(By.id("reloadForm__email")); System.out.println(emailtxt.isEnabled()); if (emailtxt.isEnabled()) { handleInputField_ByID("reloadForm__email", AppConstants.EMAIL); //Thread.sleep(500); } JavascriptExecutor js1 = (JavascriptExecutor) getDriver(); js1.executeScript("window.scrollBy(0,400)", ""); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/ul/li[3]/label/div", 5).click(); log.info("Success : Radio Button of amonut 30 is clicked"); tryToGetElementByXPath("//*[@id='prepaidReloadForm']/label/div", 5).click(); log.info("Success : checkbox is clicked"); tryToClickElementByXPath("//*[@id='proceedBtn']", 5).click(); log.info("Success : Proceed Button is clicked"); waitForPageLoad(100); Thread.sleep(500); JavascriptExecutor js = (JavascriptExecutor) getDriver(); js.executeScript("window.scrollBy(0,500)", ""); /*}catch(Exception e) { log.error("Fail : Failed to process reload of amount 30."); shutDown(); }*/ }