List of usage examples for org.openqa.selenium WebElement getAttribute
String getAttribute(String name);
From source file:com.gargoylesoftware.htmlunit.javascript.host.WebSocketTest.java
License:Apache License
/** * @throws Exception if the test fails// w w w . j ava 2 s .c o m */ @Test @Alerts({ "onError[object Event]", "onCloseListener code: 1006 wasClean: false", "onClose code: 1006 wasClean: false" }) public void eventsNoSocketServer() throws Exception { startWebServer("src/test/resources/com/gargoylesoftware/htmlunit/javascript/host", null, null, null); final WebDriver driver = getWebDriver(); driver.get(URL_FIRST + "WebSocketTest_events.html"); final WebElement logElement = driver.findElement(By.id("log")); int counter = 0; String text; do { Thread.sleep(100); text = logElement.getAttribute("value").trim().replaceAll("\r", ""); } while (text.length() > 0 && counter++ < 10); assertEquals(String.join("\n", getExpectedAlerts()), text); }
From source file:com.gargoylesoftware.htmlunit.libraries.ExtJS22Test.java
License:Apache License
private static boolean core_spotlight_isDisabled(final WebElement button) { final WebElement table = button.findElement(By.xpath("ancestor::table[1]")); return table.getAttribute("class").contains("disabled"); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * @throws Exception if an error occurs/*from ww w . j a v a 2 s . c om*/ */ @Test public void shouldBeAbleToUseArrowKeys() throws Exception { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement keyReporter = driver.findElement(By.id("keyReporter")); keyReporter.sendKeys("tet", Keys.ARROW_LEFT, "s"); assertThat(keyReporter.getAttribute("value"), is("test")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.//from w w w . ja va 2 s . c o m */ @Test public void shouldReportKeyCodeOfArrowKeys() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement result = driver.findElement(By.id("result")); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys(Keys.ARROW_DOWN); checkRecordedKeySequence(result, 40); element.sendKeys(Keys.ARROW_UP); checkRecordedKeySequence(result, 38); element.sendKeys(Keys.ARROW_LEFT); checkRecordedKeySequence(result, 37); element.sendKeys(Keys.ARROW_RIGHT); checkRecordedKeySequence(result, 39); // And leave no rubbish/printable keys in the "keyReporter" assertThat(element.getAttribute("value"), is("")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.// w w w . j a va 2 s . co m */ @Test public void shouldReportKeyCodeOfArrowKeysUpDownEvents() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement result = driver.findElement(By.id("result")); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys(Keys.ARROW_DOWN); assertThat(result.getText().trim(), containsString("down: 40")); assertThat(result.getText().trim(), containsString("up: 40")); element.sendKeys(Keys.ARROW_UP); assertThat(result.getText().trim(), containsString("down: 38")); assertThat(result.getText().trim(), containsString("up: 38")); element.sendKeys(Keys.ARROW_LEFT); assertThat(result.getText().trim(), containsString("down: 37")); assertThat(result.getText().trim(), containsString("up: 37")); element.sendKeys(Keys.ARROW_RIGHT); assertThat(result.getText().trim(), containsString("down: 39")); assertThat(result.getText().trim(), containsString("up: 39")); // And leave no rubbish/printable keys in the "keyReporter" assertThat(element.getAttribute("value"), is("")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test./* w ww.j av a 2 s .c om*/ */ @Test public void numericShiftKeys() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement result = driver.findElement(By.id("result")); final WebElement element = driver.findElement(By.id("keyReporter")); final String numericShiftsEtc = "~!@#$%^&*()_+{}:\"<>?|END~"; element.sendKeys(numericShiftsEtc); assertThat(element.getAttribute("value"), is(numericShiftsEtc)); assertThat(result.getText().trim(), containsString(" up: 16")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.//from w ww. j av a 2s . c om */ @Test public void uppercaseAlphaKeys() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement result = driver.findElement(By.id("result")); final WebElement element = driver.findElement(By.id("keyReporter")); final String upperAlphas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; element.sendKeys(upperAlphas); assertThat(element.getAttribute("value"), is(upperAlphas)); assertThat(result.getText().trim(), containsString(" up: 16")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.// ww w . ja v a2 s. co m */ @Test public void allPrintableKeys() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement result = driver.findElement(By.id("result")); final WebElement element = driver.findElement(By.id("keyReporter")); final String allPrintable = "!\"#$%&'()*+,-./0123456789:;<=>?@ ABCDEFGHIJKLMNO" + "PQRSTUVWXYZ [\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; element.sendKeys(allPrintable); assertThat(element.getAttribute("value"), is(allPrintable)); assertThat(result.getText().trim(), containsString(" up: 16")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test.//w w w . j a v a 2 s .c o m */ @Test public void testArrowKeysAndPageUpAndDown() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys( "a" + Keys.LEFT + "b" + Keys.RIGHT + Keys.UP + Keys.DOWN + Keys.PAGE_UP + Keys.PAGE_DOWN + "1"); assertThat(element.getAttribute("value"), is("ba1")); }
From source file:com.gargoylesoftware.htmlunit.selenium.TypingTest.java
License:Apache License
/** * A test./* www. j a v a2 s.c o m*/ */ @Test public void homeAndEndAndPageUpAndPageDownKeys() { final WebDriver driver = getWebDriver("/javascriptPage.html"); final WebElement element = driver.findElement(By.id("keyReporter")); element.sendKeys("abc" + Keys.HOME + "0" + Keys.LEFT + Keys.RIGHT + Keys.PAGE_UP + Keys.PAGE_DOWN + Keys.END + "1" + Keys.HOME + "0" + Keys.PAGE_UP + Keys.END + "111" + Keys.HOME + "00"); assertThat(element.getAttribute("value"), is("0000abc1111")); }